feat: animation jitter

This commit is contained in:
cha0s 2019-04-21 21:54:41 -05:00
parent 86c3a12a9e
commit f9a7db6f95

View File

@ -61,6 +61,13 @@ class AnimatedBase extends Trait {
this.entity.container.removeChild(animationView);
}
jitterFor(key) {
if (!this._animations[key] || !this._animations[key].jitter) {
return 0;
}
return this._animations[key].jitter;
}
loadAnimations() {
if (this.animationsPromise) {
return;
@ -224,11 +231,14 @@ class AnimatedBase extends Trait {
return;
}
// Only tick current animation.
const animation = this.animations[this.entity.currentAnimation];
const currentAnimation = this.entity.currentAnimation;
const animation = this.animations[currentAnimation];
if (!animation) {
return;
}
animation.tick(elapsed);
const jitter = Math.random() * this.jitterFor(currentAnimation);
const halfJitter = jitter / 2;
animation.tick(elapsed + (jitter - halfJitter));
}
}