Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Need help with sprite animation.

Author
Message
mr joe
20
Years of Service
User Offline
Joined: 12th Aug 2004
Location: Edinburger, Scotland. DBC
Posted: 12th Aug 2004 21:56
I'm just getting started but would really appreciate some help with a problem i have. I have animated a figure moving right left and jumping (though these are not the final animations, just to test the code). But when the character changes direction the animation dosen't change straight away.

I havent got much code yet so ive posted it all.

Thanks.
Lzdude69
21
Years of Service
User Offline
Joined: 21st May 2004
Location: Indiana
Posted: 12th Aug 2004 23:22
instead of using "gosub" for every action the little dude does. Do the action within the "if upkey()=1" and "endif" commands. You can also use functions, functions are probably faster in large numbers than gosubs, well gosubs win, in a sub-routine, which jumping, sorta is'nt. But if you really dont care that much about speed, which this is obviously about, slap a goto instead of a gosub, but if its in a loop (it has to be) make sure you make a function or something that continues the loop.


mr joe
20
Years of Service
User Offline
Joined: 12th Aug 2004
Location: Edinburger, Scotland. DBC
Posted: 13th Aug 2004 03:33
i think you're right the if/endif commands are better for these actions and i have changed the code.

I dont think i explained the problem very well though. When I press the right key, the sprite moves right and has the correct animation. But if i then press left the remaining frames from the right animation play before it changes to the left animation. It changes straight away when i press right from going left though.
mr joe
20
Years of Service
User Offline
Joined: 12th Aug 2004
Location: Edinburger, Scotland. DBC
Posted: 14th Aug 2004 02:19
Hey hey hey,

I still could do with a hand if anyone's interested, and here's a revised version of the animation code...



This is within a do/loop. Please please please, somebody help me.
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 14th Aug 2004 14:43
Uh... I may be barking at the moon here but your if statements for the image selection are not correct. Unless I'm very much mistaken, you can't do a if 2<x<10 statement and get it to work correctly in the manner you want it to. The proper format is if 2<x and x<10, because the term of 2<x returns either a zero or one, which will then be tested against the <10 value. Both in moving left and moving right, you have this mixed comparison, which could explain your failing animation.
S.

Any truly great code should be indisguishable from magic.
Lzdude69
21
Years of Service
User Offline
Joined: 21st May 2004
Location: Indiana
Posted: 15th Aug 2004 14:38 Edited at: 15th Aug 2004 14:40
Yep, SandraD is right.

and if you want to stop the animation NOW, then do it like this:



I used to be alienman


Coming Soon: HexTournament, Quantum Tournament
mr joe
20
Years of Service
User Offline
Joined: 12th Aug 2004
Location: Edinburger, Scotland. DBC
Posted: 17th Aug 2004 21:27
thanks sandrad, thats what my problem was, and thanks sarge aswell, i didnt think about the standing animation yet but ill need to do it, thats really helpful

Login to post a reply

Server time is: 2025-05-26 03:19:57
Your offset time is: 2025-05-26 03:19:57