refactor: frame rect calc
This commit is contained in:
parent
2952e4edf4
commit
fb19cdfc69
|
@ -37,16 +37,6 @@ class AnimatedBase extends Trait {
|
|||
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() {
|
||||
if (!this.entity.container) {
|
||||
return;
|
||||
|
@ -62,9 +52,16 @@ class AnimatedBase extends Trait {
|
|||
}
|
||||
|
||||
updateFrameRect() {
|
||||
if (this.sprite) {
|
||||
this.sprite.sourceRectangle = this.frameRect;
|
||||
if (!this.sprite) {
|
||||
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() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user