If the numbers involved are powers of two, like 2, 4, 8, 16, etc. as an alternative to storing individual states you can just apply bitwise operations to the free-running frameCounter variable you have.
For example, if you have 4 frames of animation, and want to switch every 8 frames:
Code: Select all
lda frameCounter
lsr
lsr
lsr ; A = frameCounter / 8
and #3 ; A = A % 4
; A is now either 0,1,2,3 and will change every 8 frames.
I don't do this for most of my objects, because I usually want different timings besides ones that line up with 4/8/16 etc. but I still find it's a useful alternative in some cases.
casprog wrote:Is this a common approach to timing? I figure the NMI will fire roughly 60 times a second so I can piggyback off that?
In Allegro and SDL I would get the current time and compare if the elapsed time between the last movement was greater than some timing variable.
It is a very common approach to count frames in some way, and base your animation timings off of that, yes.
This is often applicable to modern games, too, if they have a fixed framerate design (e.g. fighting games almost always do this). Choosing a fixed vs. variable framerate makes a big impact on a game's design, but with NES normally a fixed framerate approach is presumed.