Advertisement

Animation with Timers

Started by June 05, 2001 07:59 AM
2 comments, last by grasshopa55 23 years, 8 months ago
Hi I have a quick question. Up until now, all of my applications have just been tests of various techniques. After taking a look at the most recent article about frame rates, I realized that I don''t really understand the concept of using the timer for animation. I understand that it involves ( at least in the Windows world ) the function GetTickCounts(). Can anyone help me out? Thanks. Kevin ----------------------------- kevin@mayday-anime.com http://dainteractive.mayday-anime.com
-----------------------------kevin@mayday-anime.comhttp://www.mayday-anime.com
Well, the way I do it is get the current time (using GetTickCount()), add the sprite''s frame delay to that, and store it in a variable called nextTick (each sprite has its own nextTick), then every frame, check if thisTick (the current time) is greater than nextTick, and if so, change frames and add the delay to thisTick again.
You can use the timer to calculate movement too, as I explained in this post.



-Deku-chan

DK Art (my site, which has little programming-related stuff on it, but you should go anyway^_^)
Advertisement
Ok, that makes sense. One more question, how do you decide what each sprite''s frame delay is? Do you just choose and arbitrary number or is there a formula to determine the value?
Kevin

-----------------------------
kevin@mayday-anime.com
http://dainteractive.mayday-anime.com
-----------------------------kevin@mayday-anime.comhttp://www.mayday-anime.com
you just choose a number in milliseconds. For example, if you want 4 frames/sec, make it 250.
I use an animation script class that allows a different delay for each frame, but since it''s not really necessary, and soaks up an extra few bytes per frame, you could just give your sprite class a frame delay and use that for all animations frames, and just change it if you need a higher frame rate (like, your sprite will move faster when running than he does walking).



-Deku-chan

DK Art (my site, which has little programming-related stuff on it, but you should go anyway^_^)

This topic is closed to new replies.

Advertisement