forums

TNT Basic Forums > Programming Q&A
Switching image banks & animations
< Last Thread     Next Thread >
Author
Thread        Post A Reply

08-22-2003 18:01

Posted by:
mark_667

Location:
England

Click Here to Email mark_667   Find more posts by mark_667

Hi,
In the code below, I am animating sprites (this one has a stick man bungee jumping :-)) where I use existing sprites from one bank to a point, before I have to switch to another one, this avoids pointlessly duplicationg sprites that already exist in another bank hen I can switch between them. However, I found that although the image 161 draws, the sprites from the second image bank do not appear. Also, the sprite rotation seems to be causing some kind of obscure syntax error. I have also tried using the image variable as this is what I'm animating: rotation=rotate sprite (image), but this makes no difference. The code is included below...

graphics mode 640,480
frame rect 0,0 to 640,480
Set Framerate max

Global int image=0, n=0
Global int x=320, y=240
load images 129
int x=40,y=20
int spriteXVelocity=3, spriteYVelocity=10
int rotation=10

repeat
draw picture 161 'Cliff edge
sprite n,x,y,image
image=image+1
draw frame
until image>8

if image>8 'End of sprites in 1st image bank
image=0
unload images 129
end if

load images 132
repeat
draw picture 161
sprite n,x,y,image 'Start 2nd set
image=image+1
draw frame
until image>3

if image>3
repeat
draw picture 161
x=x+spriteXVelocity 'Fall about 30 pixels, rotating through 90 degrees until upside down
y=y+spriteYvelocity
rotation=rotate sprite (n,x,y,image)
rotation=rotation+10 'increment rotation in 10 degrees each time
until y=400
end if
if y=400
repeat
y=y-spriteYVelocity 'Bounce back up a bit here to simulate elastisity in chord
until y<350
end if

thanks,
Mark_667

08-23-2003 00:10

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

I haven't gone through all your code, but this is my impression:

i think you are loding and unloading image banks right in the middle of the animation. You should just keep them all loaded and use set image bank spriteID,bankToUse

08-23-2003 18:35

Posted by:
mark_667

Location:
England

Click Here to Email mark_667   Find more posts by mark_667

Sprite doesn't rotate

Thanks for the tip Matthew, it works and now looks like this:

graphics mode 640,480
frame rect 0,0 to 640,480
Set Framerate max

load images 129
load images 132
int x=110,y=20
spriteXVelocity=5
spriteYVelocity=10
int rotation=10
image=0
n=0

repeat
draw picture 161
sprite n,x,y,image
draw frame
repeat
sprite n,x,y,image
draw frame
x=x+spriteXVelocity 'Does run-up here
y=y+spriteYVelocity
until x>120
if x>120
spriteXVelocity=5 'Reset variable so stick person falls more normally and doesn't fly!
image=image+1
end if
until image=8 'Jumps off cliff edge here

if image=8 'End of sprites in 1st image bank, reset image variable for next bank
image=0
set image bank n,132
unload images 129
end if

repeat
draw picture 161
sprite n,x,y,image
draw frame
x=x+spriteXVelocity 'This part makes sprite fall while changing
y=y+spriteYVelocity
image=image+1
until image=3

if image=3
repeat
sprite n,x,y,image 'When sprite 3 is reached fall straight down only
draw frame
spriteXVelocity=0
y=y+spriteYVelocity
set sprite rotation n, rotation'Increment rotation in 10 degrees each time to give a tumbling effect
rotation=sprite rotation (n)
rotation=rotation+10
until y=400
end if

if y=400
repeat
sprite n,x,y,image 'Bounce back up a bit here to simulate elastisity in chord
draw frame
spriteYVelocity=3
y=y-spriteYVelocity
until y<350
end if

Although there is a slightly noticeable pause between TNT switching image banks I'm fairly confident this will be negligable on a faster computer. However, the sprite still does not rotate, even though there are no syntaxing errors, etc anyone any ideas on this?

thanks,
Mark_667

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.