refactor: frame rect calc
This commit is contained in:
parent
2952e4edf4
commit
fb19cdfc69
|
@ -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() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user