feat: animation jitter
This commit is contained in:
parent
86c3a12a9e
commit
f9a7db6f95
|
@ -61,6 +61,13 @@ class AnimatedBase extends Trait {
|
||||||
this.entity.container.removeChild(animationView);
|
this.entity.container.removeChild(animationView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jitterFor(key) {
|
||||||
|
if (!this._animations[key] || !this._animations[key].jitter) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return this._animations[key].jitter;
|
||||||
|
}
|
||||||
|
|
||||||
loadAnimations() {
|
loadAnimations() {
|
||||||
if (this.animationsPromise) {
|
if (this.animationsPromise) {
|
||||||
return;
|
return;
|
||||||
|
@ -224,11 +231,14 @@ class AnimatedBase extends Trait {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Only tick current animation.
|
// Only tick current animation.
|
||||||
const animation = this.animations[this.entity.currentAnimation];
|
const currentAnimation = this.entity.currentAnimation;
|
||||||
|
const animation = this.animations[currentAnimation];
|
||||||
if (!animation) {
|
if (!animation) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
animation.tick(elapsed);
|
const jitter = Math.random() * this.jitterFor(currentAnimation);
|
||||||
|
const halfJitter = jitter / 2;
|
||||||
|
animation.tick(elapsed + (jitter - halfJitter));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user