forked from arne/asdf-games
Fixed issues in AnimManager.js
This commit is contained in:
parent
3a210d1b60
commit
cb46be0088
@ -5,6 +5,12 @@ class Anim {
|
||||
this.reset();
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.frame = this.frames[0];
|
||||
this.curFrame = 0;
|
||||
this.curTime = 0;
|
||||
}
|
||||
|
||||
update(dt) {
|
||||
const { rate, frames } = this;
|
||||
if ((this.curTime += dt) > rate) {
|
||||
@ -13,20 +19,14 @@ class Anim {
|
||||
this.curTime -= rate;
|
||||
}
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.frame = this.frames[0];
|
||||
this.curFrame = 0;
|
||||
this.curTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
class AnimManager {
|
||||
constructor(e) {
|
||||
constructor(e = { x: 0, y: 0 }) {
|
||||
this.anims = {};
|
||||
this.running = false;
|
||||
this.frameSource = e.frame || e;
|
||||
this.currrent = null;
|
||||
this.current = null;
|
||||
}
|
||||
|
||||
add(name, frames, speed) {
|
||||
@ -42,6 +42,7 @@ class AnimManager {
|
||||
const anim = anims[current];
|
||||
anim.update(dt);
|
||||
|
||||
// Sync the tileSprite frame
|
||||
frameSource.x = anim.frame.x;
|
||||
frameSource.y = anim.frame.y;
|
||||
}
|
||||
@ -61,3 +62,4 @@ class AnimManager {
|
||||
}
|
||||
|
||||
module.exports = AnimManager;
|
||||
|
Loading…
Reference in New Issue
Block a user