From 68b908ec436d3a18c4acc96458b7496769bdad58 Mon Sep 17 00:00:00 2001 From: cha0s Date: Thu, 17 Oct 2024 23:07:32 -0500 Subject: [PATCH] feat: zIndex --- app/ecs/components/sprite.js | 1 + app/react/components/pixi/entity.js | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/ecs/components/sprite.js b/app/ecs/components/sprite.js index aa19198..0fe772f 100644 --- a/app/ecs/components/sprite.js +++ b/app/ecs/components/sprite.js @@ -215,5 +215,6 @@ export default class Sprite extends Component { source: {type: 'string'}, speed: {type: 'float32'}, tint: {defaultValue: 0xffffff, type: 'uint32'}, + zIndex: {defaultValue: 65535, type: 'uint16'}, }; } diff --git a/app/react/components/pixi/entity.js b/app/react/components/pixi/entity.js index 7d520c0..165d0d2 100644 --- a/app/react/components/pixi/entity.js +++ b/app/react/components/pixi/entity.js @@ -106,10 +106,17 @@ export default class Entity { const {x, y} = this.entity.Position; this.container.x = x; this.container.y = y; - this.container.zIndex = y; + if (this.entity.Sprite?.zIndex === 65535) { + this.container.zIndex = y; + } } if (Sprite) { const {diffuse, normals} = this; + if (!this.attached || 'zIndex' in Sprite) { + this.container.zIndex = this.entity.Sprite?.zIndex === 65535 + ? this.entity.Position.y + : this.entity.Sprite.zIndex; + } if (!this.attached || 'alpha' in Sprite) { diffuse.alpha = normals.alpha = this.entity.Sprite.alpha; }