LoginLogin

Player and enemy moving at different speeds

Root / Programming Questions / [.]

DavidWoodSuperGuyCreated:
... You can't count frames (at least that I know of, ...
Yes, you can. MAINCNT stores the number of drawn frames since start. You can store MAINCNT+7 in a var (NEXT) on startup, and in your main loop, if MAINCNT >= NEXT, do the enemy routine and do NEXT=MAINCNT+7 again.
I'd strongly recommend NEXT=NEXT+7 instead. If your loop happens to take more than 1 frame sometimes, then NEXT=MAINCNT+7 will be less than 1/7th of the frame rate, and diverging from it more if more iterations take longer. NEXT=NEXT+7 will ensure a constant frequency (as long as an iteration doesn't take as long as 7 frames); the phase may be a bit jittery, that's unavoidable if one iteration takes that long, but the frequency will be steady. And of course, all of this is bad advice, because NEXT is a reserved keyword. Pick another name.
Even so, what type is this variable? Integer? If it's integer, you could do NEXT% and get away with it, I suppose. But nobody suffixes properly anyway so idk.