feat: isAnimating
This commit is contained in:
parent
a1eb00b649
commit
a723065a92
|
@ -30,6 +30,7 @@ class AnimatedBase extends Trait {
|
|||
this.animations = {};
|
||||
this.animationViews = undefined;
|
||||
this.animationsPromise = undefined;
|
||||
this._isAnimating = true;
|
||||
}
|
||||
|
||||
destroy() {
|
||||
|
@ -57,6 +58,10 @@ class AnimatedBase extends Trait {
|
|||
this.entity.container.removeChild(animationView);
|
||||
}
|
||||
|
||||
set isAnimating(isAnimating) {
|
||||
this._isAnimating = isAnimating;
|
||||
}
|
||||
|
||||
loadAnimations() {
|
||||
if (this.animationsPromise) {
|
||||
return;
|
||||
|
@ -160,6 +165,7 @@ class AnimatedBase extends Trait {
|
|||
|
||||
listeners() {
|
||||
return {
|
||||
|
||||
currentAnimationChanged: (oldKey) => {
|
||||
// Reset old animation.
|
||||
const oldAnimation = this.animations[oldKey];
|
||||
|
@ -176,6 +182,7 @@ class AnimatedBase extends Trait {
|
|||
this.hideAnimation(oldKey);
|
||||
this.showAnimation(this.entity.currentAnimation);
|
||||
},
|
||||
|
||||
directionChanged: () => {
|
||||
// All animations track direction.
|
||||
for (const key in this.animations) {
|
||||
|
@ -183,6 +190,11 @@ class AnimatedBase extends Trait {
|
|||
animation.direction = this.entity.direction;
|
||||
}
|
||||
},
|
||||
|
||||
dying: () => {
|
||||
this._isAnimating = false;
|
||||
},
|
||||
|
||||
traitAdded: (type) => {
|
||||
if (-1 === [
|
||||
'animated',
|
||||
|
@ -197,6 +209,9 @@ class AnimatedBase extends Trait {
|
|||
}
|
||||
|
||||
tick(elapsed) {
|
||||
if (!this._isAnimating) {
|
||||
return;
|
||||
}
|
||||
// Only tick current animation.
|
||||
const animation = this.animations[this.entity.currentAnimation];
|
||||
if (!animation) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user