perf: opts
This commit is contained in:
parent
353d1aec5d
commit
0e5c54293b
|
@ -34,6 +34,7 @@ class AnimatedBase extends Trait {
|
|||
this.animations = {};
|
||||
this.animationViews = undefined;
|
||||
this.animationsPromise = undefined;
|
||||
this._currentAnimation = this.entity.currentAnimation;
|
||||
}
|
||||
|
||||
destroy() {
|
||||
|
@ -115,7 +116,7 @@ class AnimatedBase extends Trait {
|
|||
const animationView = this.animationViews[key];
|
||||
animationView.position = this.offsetFor(key);
|
||||
// Ensure animation is made visible upfront.
|
||||
const isCurrentAnimation = key === this.entity.currentAnimation;
|
||||
const isCurrentAnimation = key === this._currentAnimation;
|
||||
if (isCurrentAnimation) {
|
||||
this.showAnimation(key);
|
||||
}
|
||||
|
@ -157,7 +158,7 @@ class AnimatedBase extends Trait {
|
|||
return {
|
||||
|
||||
visibleBoundingBoxes: () => {
|
||||
const key = this.entity.currentAnimation;
|
||||
const key = this._currentAnimation;
|
||||
const animation = this.animations[key];
|
||||
if (!animation) {
|
||||
return [0, 0, 0, 0];
|
||||
|
@ -179,7 +180,8 @@ class AnimatedBase extends Trait {
|
|||
listeners() {
|
||||
return {
|
||||
|
||||
currentAnimationChanged: (oldKey) => {
|
||||
currentAnimationChanged: (oldKey, currentAnimation) => {
|
||||
this._currentAnimation = currentAnimation;
|
||||
// Reset old animation.
|
||||
const oldAnimation = this.animations[oldKey];
|
||||
if (oldAnimation) {
|
||||
|
@ -193,7 +195,7 @@ class AnimatedBase extends Trait {
|
|||
}
|
||||
// Swap the animation.
|
||||
this.hideAnimation(oldKey);
|
||||
this.showAnimation(this.entity.currentAnimation);
|
||||
this.showAnimation(this._currentAnimation);
|
||||
},
|
||||
|
||||
directionChanged: () => {
|
||||
|
@ -231,14 +233,18 @@ class AnimatedBase extends Trait {
|
|||
return;
|
||||
}
|
||||
// Only tick current animation.
|
||||
const currentAnimation = this.entity.currentAnimation;
|
||||
const currentAnimation = this._currentAnimation;
|
||||
const animation = this.animations[currentAnimation];
|
||||
if (!animation) {
|
||||
return;
|
||||
}
|
||||
const jitter = Math.random() * this.jitterFor(currentAnimation);
|
||||
const jitterAmount = this.jitterFor(currentAnimation);
|
||||
if (jitterAmount > 0) {
|
||||
const jitter = Math.random() * jitterAmount;
|
||||
const halfJitter = jitter / 2;
|
||||
animation.tick(elapsed + (jitter - halfJitter));
|
||||
elapsed += jitter - halfJitter;
|
||||
}
|
||||
animation.tick(elapsed);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user