diff --git a/app/react/components/pixi/entities.jsx b/app/react/components/pixi/entities.jsx index 3705ad9..a752d38 100644 --- a/app/react/components/pixi/entities.jsx +++ b/app/react/components/pixi/entities.jsx @@ -48,8 +48,7 @@ export default function Entities({monopolizers, particleWorker}) { entities.current[id].setMainEntity(); } } - entities.current[id].update(payload[id]); - entities.current[id].addToContainer(containerRef.current); + entities.current[id].update(payload[id], containerRef.current); } }, [debug, ecs, mainEntity]) useEffect(() => { diff --git a/app/react/components/pixi/entity.js b/app/react/components/pixi/entity.js index 85b9ff8..a9e1049 100644 --- a/app/react/components/pixi/entity.js +++ b/app/react/components/pixi/entity.js @@ -28,14 +28,6 @@ export default class Entity { this.debug.addChild(this.colliderAabb); this.debug.addChild(this.visibleAabb); } - addToContainer(container) { - if (this.attached || !container) { - return; - } - container.addChild(this.container); - container.addChild(this.debug); - this.attached = true; - } static async loadAsset(source = '') { if (!this.assets['']) { const {Texture} = await import('@pixi/core'); @@ -98,7 +90,7 @@ export default class Entity { } return texture; } - update({Direction, Light, Position, Sprite, VisibleAabb}) { + update({Direction, Light, Position, Sprite, VisibleAabb}, container) { if (Light) { if (!this.light) { this.light = new PointLight( @@ -190,5 +182,11 @@ export default class Entity { if (this.isMainEntity) { this.interactionAabb.redraw(this.entity.Interacts.aabb()); } + if (this.attached || !container) { + return; + } + container.addChild(this.container); + container.addChild(this.debug); + this.attached = true; } }