forums

TNT Basic Forums > Programming Q&A
Sprite animation
< Last Thread     Next Thread >
Author
Thread        Post A Reply

08-09-2003 17:00

Posted by:
mark_667

Location:
England

Click Here to Email mark_667   Find more posts by mark_667

Hi,
I'm making a simple animation, but to stop the sprite going off the screen, I use if statements to change the x decrement that moves the character to an increment so it moves towards the other side of the screen. The same happens at the other side, but obviously the other way around. However, when it's run this only partly works as each time the loop is executed it decrements again, having the effect of pullling the character back from the way it came. As you can see below, the x=x-2 variable has to b there, otherwise it wouldn't move at all to start with! Code included below:

'Programmed by: Mark
fade down
graphics mode 640,480
frame rect 0,0 to 640,480
Set Framerate max
load images 128

int image=0, n=0
int x=320, y=240

fade up
repeat
sprite n,x,y,image
x=x-2
image=image+1
draw frame

if sprite x(n)<10 then x=x+12 'Make it so sprite does not walk off screen.
if sprite x(n)>=640 then x=x-2

int colour=random (0,255)
int r = set red component(colour,r)
int g = set green component(colour,g)
int b = set blue component(colour,b)
colour = make colour (r,g,b)
set pen colour colour
delay 100 'This way we can make it so the colours aren't changing too fast without affecting the framerate
paint canvas

if image>4 'End of sprites
image=0
end if
forever

thanks,
Mark_667

08-09-2003 18:19

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Use a variable to keep track of which direction the sprite is going and change the x accordingly.

quote:

fade down
graphics mode 640,480
frame rect 0,0 to 640,480
Set Framerate max
load images 128

int image=0, n=0
int x=320, y=240
int spriteXVelocity=-2
fade up
repeat
sprite n,x,y,image

image=image+1
draw frame

if sprite x(n)<10 then spriteXVelocity=2 'Make it so sprite does not walk off screen.
if sprite x(n)>=640 then spriteXVelocity=-2
x=x+spriteXVelocity

int colour=random (0,255)
int r = set red component(colour,r)
int g = set green component(colour,g)
int b = set blue component(colour,b)
colour = make colour (r,g,b)
set pen colour colour
delay 100 'This way we can make it so the colours aren't changing too fast without affecting the framerate
paint canvas

if image>4 'End of sprites
image=0
end if
forever

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.