forums

TNT Basic Forums > Programming Q&A
Move an animating sprite?
< Last Thread     Next Thread >
Author
Thread        Post A Reply

07-12-2003 17:29

Posted by:
ohlsonvox

Click Here to Email ohlsonvox   Find more posts by ohlsonvox

I an new to TNT Basic, but was wondering how I can make a sprite animate through a series of frames while mocing across the screen?

I tried to figure it out in the documentation, but did not understand the process. Anyone's help would be appreciated.

ohlssonvox

07-12-2003 18:35

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

There are two ways: the classic way and the moan way. I will only talk about the classic way as I chose not to use moan. ( ' is placed before a comment ). This is very basic example with very simple movement. You will probably need more help, but this is a start.


graphcis mode 640,480

int x=100,y=100 'give choords so that the sprite id located
int picture=5 ' give a picture to the sprite

load images 128 ' load image bank 128
'lets say the animation pictures are from 5 to 10 in the bank

int execution=true 'the execution is true
while execution 'repeat until the exution isn't true anymore

x=x+1
y=y+1 ' the choords are now moving diagonnaly towards the bottom right corner

picture=picture+1 'the sprite has a different image every frame

if picture>10 then picture=5
'if the picture selected isn't part of the animation, ( animation ends at pict 10 )
'then it goes back to the start of the animation ( anmation starts at pict 5 )

sprite 1,x,y,picture ' diplay the sprite

draw frame

wend ' where the part to be repeated ends

07-12-2003 18:55

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

You could use MOAN to do it automatically, or you could do it manually.
Let's say you have two frames for each direction. 0 and 1 are for up, 2 and 3 for right, 4 and 5 for down, and 6 and 7 for left.
Manually:

int x, y, ID=1, frame, image
repeat
If up
if frame=1 then image=0
if frame=2 then image=1
y=y-5
else if right
if frame=1 then image=2
if frame=2 then image=3
x=x+5
else if down
if frame=1 then image=4
if frame=2 then image=5
y=y+5
else if left
if frame=1 then image=6
if frame=2 then image=7
x=x-5
end if
sprite ID,x,y,image
frame=frame+1
if frame=3 then frame=1
draw frame
while not mouse button

MOAN:
int x, y, ID=1, frame, image
sprite ID,0,0,0
repeat
If up
move sprite ID,0,-5,-1 'in one frame, move up 5 pixels
animate sprite ID,-1,0,1 to 1,1 'animate for -1 'frames(forever)
else if right
move sprite ID,5,0,-1
animate sprite ID,-1,2,1 to 3,1
else if down
move sprite ID,0,5,-1
animate sprite ID,-1,4,1 to 5,1
else if left
move sprite ID,-5,0,-1
animate sprite ID,-1,6,1 to 7,1
end if
draw frame
while not mouse button

07-12-2003 19:00

Posted by:
ohlsonvox

Click Here to Email ohlsonvox   Find more posts by ohlsonvox

Thanks!

I will give these a go. I was ale to hack something that animates the sprite, but it looks terrible and I know it is NOT the right way. I will give your suggestions a go.

By the way, what is all the controversy abut MOAN? I hear people who love it nd people who hate it. What gives?

by the way here is my terrible code:

sprite 4,bumperx,bumpery,eggimage

draw frame
sprite off 4
eggimagecnt=eggimagecnt+1

if eggimage>10 then eggimage=4
if eggimagecnt=3 then eggimage=eggimage+1
if eggimagecnt=3 then eggimagecnt=0

ohlssonvox

07-12-2003 19:09

Posted by:
ohlsonvox

Click Here to Email ohlsonvox   Find more posts by ohlsonvox

Too FAST!!???

Matthew I tried your example and it seems to work fine, but it animates too fast. I tried running it in "hardware" mode on my machine and it runs much better, but I have found hardware mode makes everything run too slow. My machine is an old iMAC 233MhZ.

I would prefer to program without hardware mode. My anim had 6 frames , it is an egg spinning around, but is spinning too fast.

ohlssonvox

07-13-2003 14:09

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

Oh yeah, I didn't talk about slowing it down. You may declare the image as a float:

float image=5

...

image=image+0.2


' I guess it works :)

07-13-2003 14:51

Posted by:
ohlsonvox

Click Here to Email ohlsonvox   Find more posts by ohlsonvox

It worked!

Thanks. I thought of trying to make the fram advance by something less than 1, but I thought it would not work unless I was using an integer. Now I am on my way! Thanks.

ohlssonvox

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.