refactor: frame rect calc

This commit is contained in:
cha0s 2019-03-19 11:29:07 -05:00
parent 2952e4edf4
commit fb19cdfc69

View File

@ -37,16 +37,6 @@ class AnimatedBase extends Trait {
this.loadSpriteImageIfPossible(); this.loadSpriteImageIfPossible();
} }
get frameRect() {
const direction = ('direction' in this.entity) ? this.entity.direction : 0;
return [
this.entity.currentFrame * this.frameSize[0],
direction * this.frameSize[1],
this.frameSize[0],
this.frameSize[1],
];
}
loadSpriteImageIfPossible() { loadSpriteImageIfPossible() {
if (!this.entity.container) { if (!this.entity.container) {
return; return;
@ -62,9 +52,16 @@ class AnimatedBase extends Trait {
} }
updateFrameRect() { updateFrameRect() {
if (this.sprite) { if (!this.sprite) {
this.sprite.sourceRectangle = this.frameRect; return;
} }
const direction = ('direction' in this.entity) ? this.entity.direction : 0;
this.sprite.sourceRectangle = [
this.entity.currentFrame * this.frameSize[0],
direction * this.frameSize[1],
this.frameSize[0],
this.frameSize[1],
];
} }
listeners() { listeners() {