gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Timing events, the appropriate way...

#22500 - Datch - Wed Jun 23, 2004 3:23 am

Hi all,

I'm looking for a way to synchronize my game-in-progress (animations, events and all this stuff). I solved my problem with multiple vBlanks counters, one resetting every 2 vBlanks, another every 4 vBlanks, 10th, 20th and so on. I wanted to avoid doing many modulos with only one counter. Is that the good way to do stuff or there is a more professionnal method?

Thanks in advance...
_________________
Visit SR-388 now and get a 40% discount!

#22503 - tepples - Wed Jun 23, 2004 3:30 am

Datch wrote:
I'm looking for a way to synchronize my game-in-progress (animations, events and all this stuff). I solved my problem with multiple vBlanks counters, one resetting every 2 vBlanks, another every 4 vBlanks, 10th, 20th and so on. I wanted to avoid doing many modulos with only one counter.

Timing everything based on dividers of vblank is how the pros do it.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#22504 - poslundc - Wed Jun 23, 2004 3:49 am

Counting VBlanks is the way to go. For any "entity" you need to keep track of, use two fixed-point variables. One variable keeps track of the progress from frame-to-frame, and the other variable says how much to increment each frame.

So for example, if I have an animation that I want to advance to the next frame every 4 VBlanks, I could use a 24.8 counter and increment it by 64 each VBlank. I then just shift right by 8 to determine what frame I am on.

Dan.