I have been experimenting with the devkitARM toolchain for NDS homebrew recently. Something I would like better understand, however, is how to control sprite animation speeds. The only way I know of doing this is by ‘counting frames’. For example, the following code could be placed into the “animate_simple” example included with devkitpro:
int main(void) {
int frame = 0;
...
while(1) {
...
if(++frame > 9)
frame = 0;
}
return 0;
}
This is generally fine, but it ensures that all the animation initialized in the main loop runs at a set speed. How would I go about having two different sprites, each animating at different speeds? Any insight would be greatly appreciated.
Use a separate frame counter for each sprite. For example, you can create a sprite struct:
Give
delaysmall value for faster animation, and a larger value for slow animation.Sample Usage:
Note:
Since you are targeting only one platform, the best way to control animation speed is to monitor the frame rate ( or “counting frames” as you call it ). Good thing about programming for consoles is, you don’t have to set timed delays. Since all console devices of the same model usually run at the same speed, so the animation speed you get on your machine ( or emulator ) will be the same everyone gets. Different Processors Speeds are a real headache when programming for the PC.