alpha
alpha copied to clipboard
Relative depths for child Visuals
Current depth values are absolute. If you have a composite Sprite made up of many child Sprites and you change the depth of the parent, the depth of the children won't change together with it, which is inconvenient.
Visual
could have a relative_depth
field. If relative_depth is non-null and a parent is set, the child's depth
will be set to parent.depth + relative_depth. The child's depth should also change when the parent's depth changes.
This behaviour can be mimicked by overriding update() to update the child's depth every frame, but it seems more efficient and organized to have in-built support for it.
(If this is ok, I can make a pull request.)
Just my two cents, but I also think something like this would be useful.
Good idea! However, it might be confusing to have both depth
and relative_depth
- what is the behavior if both are set?
I usually do something like the following for handling relative depths:
class SomeEntity extends luxe.Sprite {
var icon :luxe.Sprite;
var text :luxe.Text;
public function new(options :SpriteOptions) {
super(options);
icon = new Sprite({
// ...
parent: this,
batcher: options.batcher,
scene: options.scene,
depth: options.depth + 0.01
});
text = new luxe.Text({
// ...
parent: this,
batcher: options.batcher,
scene: options.scene,
depth: options.depth + 0.02
});
}
}
I suggest to make function in Luxe class:
new Sprite({
name: "sprite1",
depth: 1, //depth 3
});
new Sprite({
name: "sprite2",
depth: 1.1, //depth 3.1
});
Luxe.something.relative_depth("sprite", 2);
So, every sprite with name "sprite" will have depth 2 + original depth