forums

TNT Basic Forums > Programming Q&A
Problem animating sprite while moving it
< Last Thread     Next Thread >
Author
Thread        Post A Reply

12-30-2005 19:21

Posted by:
NickFalk

Location:
Oslo, Norway

Find more posts by NickFalk

Hi there first posting and hopefully I won't have to bother you guys (and gals?) too often. Like what I see from this sweet little basic dialect a lot so far, but seem unable to figure out how to animate a sprite while moving it. My loop looks like this:

quote:

repeat

if up
move sprite 2,0,-2,4
animate sprite 2,-1, 0,3 to 2,3
end if

if down
move sprite 2,0,2,4
animate sprite 2,2, 6,3 to 8,3
end if

if right
set sprite x flip 2,0
move sprite 2,2,0,4
animate sprite 2,-1, 4,3 to 5,3
end if

if left
set sprite x flip 2,1
move sprite 2,-2,0,4
animate sprite 2,-1, 4,3 to 5,3
end if

draw frame
until mouse button



...and the sprite doesn't start animating until I actually stop moving it with the arrow-keys.

Any help would be very welcome. :)

12-31-2005 00:34

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

You basically got it...

You're right, but every time you test for a key you re-start the animation, so it never gets a chance to do anything. You need to test if the direction has 'changed' since the last poll of the keyboard, and set the anim string up if it has. There are two ways of doing this, the easiest (but not necesarily the quickest) is to hold four boolean values (yes or no) which contain the status of the keys last time round. Your code would then be something like:

if left

if not leftLastTimeRound 'just pressed it...
'set up animation and movement...
leftLastTimeRound=true
else
'just do movement as animation is already set (left was pressed last time)
end if

else 'i.e. not left... (Wish I could indent posts.)
leftLastTimeRound=false
end if


Give this a go and see what happens, you should find it solves your problem, but if you need anything else then please do drop us a line...

Danny (nods)

12-31-2005 10:18

Posted by:
NickFalk

Location:
Oslo, Norway

Find more posts by NickFalk

Thanks a lot that did the trick all right! :)
Oh Happy New Year by the way!

12-31-2005 10:50

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

You're Welcome!

And a Happy New Year to you too... Don't get too drunk 8) !

Danny (nods)

12-31-2005 11:27

Posted by:
NickFalk

Location:
Oslo, Norway

Find more posts by NickFalk

I probably will, either to:

a.) ...celebrate Liverpool's 10th consecutive win.
b.) ...drown my sorrows if they manage to loose.

Anyway, as we have a one hour head start compared to you lot over in blighty I should at least be one hour drunker er, more drunk. :p

12-31-2005 11:39

Posted by:
NickFalk

Location:
Oslo, Norway

Find more posts by NickFalk

quote:

repeat
if reds=victory then getdrunktocelebrate()
if reds=loss then getdrunktoforget()
until end of season

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.