silphius/app/ecs-systems/run-animations.js
2024-06-27 13:57:30 -05:00

26 lines
490 B
JavaScript

import {System} from '@/ecs/index.js';
export default class ControlMovement extends System {
static queries() {
return {
default: ['Sprite'],
};
}
tick(elapsed) {
for (const {Sprite} of this.select('default')) {
if (0 === Sprite.speed) {
continue;
}
Sprite.elapsed += elapsed / Sprite.speed;
while (Sprite.elapsed > 1) {
Sprite.elapsed -= 1;
Sprite.frame = (Sprite.frame + 1) % Sprite.frames;
}
}
}
}