Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Relative depths for child Visuals #284

Open
Aleph0Null opened this issue Jun 6, 2015 · 3 comments
Open

Relative depths for child Visuals #284

Aleph0Null opened this issue Jun 6, 2015 · 3 comments

Comments

@Aleph0Null
Copy link

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.)

@le-doux
Copy link
Contributor

le-doux commented Aug 10, 2016

Just my two cents, but I also think something like this would be useful.

@anissen
Copy link
Contributor

anissen commented Aug 10, 2016

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
        });
    }
}

@ghost
Copy link

ghost commented Aug 10, 2016

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants