diff --git a/packages/graphics/traits/visible.trait.js b/packages/graphics/traits/visible.trait.js index 09b4733..fb4cab7 100644 --- a/packages/graphics/traits/visible.trait.js +++ b/packages/graphics/traits/visible.trait.js @@ -94,13 +94,6 @@ export class Visible extends decorate(Trait) { this.entity.visibleScale = I.List(scale); } - shouldSynchronizePosition() { - if (!this._container) { - return false; - } - return this._container && this.trackPosition; - } - synchronizePosition() { if (!this.entity.is('positioned')) { return; @@ -133,7 +126,7 @@ export class Visible extends decorate(Trait) { } listeners() { - const listeners = { + return { isVisibleChanged: () => { if (!this._container) { @@ -153,6 +146,16 @@ export class Visible extends decorate(Trait) { this.translateVisibleAabb(); }, + traitAdded: (type) => { + if (-1 === [ + 'visible', + 'positioned', + ].indexOf(type)) { + return; + } + this.synchronizePosition(); + }, + visibleScaleChanged: () => { const scale = this.entity.visibleScale; this._visibleScale = [scale.get(0), scale.get(1)]; @@ -163,18 +166,6 @@ export class Visible extends decorate(Trait) { }, }; - if (this.shouldSynchronizePosition()) { - listeners.traitAdded = (type) => { - if (-1 === [ - 'visible', - 'positioned', - ].indexOf(type)) { - return; - } - this.synchronizePosition(); - }; - } - return listeners; } methods() { @@ -188,9 +179,7 @@ export class Visible extends decorate(Trait) { } renderTick(elapsed) { - if (this.shouldSynchronizePosition()) { - this.synchronizePosition(); - } + this.synchronizePosition(); } translateVisibleAabb() {