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.

Coding > Counting Frames

#10342 - RaBBi - Tue Sep 02, 2003 11:23 pm

Hi,

my "today" problem (lol) is about detecting a certain amount of frames as an event to start some operation.

Each VBlank, I ++ my g_Frames variable.

And in a function (which scroll a BG), I would like to detect the Xth frame to scroll++ my BG.

I use the '%' operator in a 'if' sequence like this :

Code:


iCount=2;

if(g_NewFrame && g_Frames%iCount)


But the smaller the 'iCount' variable is, the slower the scroll is.

And of course, the bigger the 'iCount' variable is, the faster the scroll is.

But in my mind, I thought there would be the inverse.

What's wrong in mine ? lol
_________________
Sorry for my poor english, but it would be worst for you to understand me if I speak in my native language, French ^^

#10343 - tepples - Tue Sep 02, 2003 11:30 pm

For one thing, '%' is a very slow operator on architectures with no hardware divide, such as the ARM7.

For another, you are describing an equation that's true when the remainder is not zero. If you want to slow it down, make the equation true when the remainder is zero.

Best option is to have a variable which you increment each vblank. Then when it reaches or surpasses iCount, set it back to zero and load the next animation frame. If you have several animations running simultaneously (such as sprite cels), you'll want to make this a field in the struct that describes each animation.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#10349 - RaBBi - Wed Sep 03, 2003 1:06 am

thank you tepples !

I understand the first part of your answer and I'll use a frame count and test if equal to iCount then reset it ^^

But I'll use later the trick about sprite animation/struct that you recommended me cause I'm still a newbie and sprite animation in my code is still very simple.

But as I use struct for my sprite yet, I think I understand what do you mean and what field in my struct I may use.

I'll post if I encount problem about it, thanx ^^
_________________
Sorry for my poor english, but it would be worst for you to understand me if I speak in my native language, French ^^