feat: zIndex

This commit is contained in:
cha0s 2024-10-17 23:07:32 -05:00
parent 62f1584a42
commit 68b908ec43
2 changed files with 9 additions and 1 deletions

View File

@ -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'},
};
}

View File

@ -106,10 +106,17 @@ export default class Entity {
const {x, y} = this.entity.Position;
this.container.x = x;
this.container.y = 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;
}