Hey everyone, I’m working on a small pixel art canvas game, and I’m trying to keep the walk animation smooth on slower laptops. When one frame stalls, my update loop sometimes jumps two or three sprite frames, and the character looks like it briefly plays frames in the wrong order instead of just running faster.
let frame = 0;
let acc = 0;
const step = 100;
function update(dt) {
acc += dt;
while (acc >= step) {
frame = (frame + Math.floor(acc / step)) % 6;
acc -= step;
}
}
Am I handling accumulated time wrong here, and what is the simple safe way to advance sprite sheet frames without weird skips when delta time suddenly gets big?
BobaMilk