This is the first game of mine where animations were strongly linked to the game logic (not code-wise, I meant it's as hints to the player), and I have realized that I've been doing animations wrong this whole time, for my code before was (in pseudo-pseudo-code):
Rect Animation::update(float delta) {
if(playing) {
frame = fmodf(frames + frame + delta * fps, frames);
}
return /* calculate sprite in spritesheet with `frame`. */;
}
Now, some would probably immediately realize that `delta` here is imprecise. At, say, a framerate of 60fps, delta would equal `0.016667`. In one real second that would all add up to `1.00002`, not `1`!
I thought about calculating the frame number with something more stable, such as `SDL_GetTicks()` in SDL2, but doing it this way makes pausing the animation more difficult (Unless I'm wrong here, which I hope in this case).
Another question, since animations are important for gameplay, and thus they must be synchronized, I thought about setting animation delta to the game timestep (1 / 60 in this case), would that be a good idea or would that be noticeable?