Jump to content

Display child sprite behind parent sprite.


Arcanorum
 Share

Recommended Posts

So I have a player class that extends from sprite, and I have added another sprite to it as a child.

The child that is added is always in front of the sprite of the parent.

 

Given that sprites can be used like groups, which is what I am doing here, it seems as if the parent's sprite itself isn't taken into account when reordering children draw orders.

 

How do I make the sprite of the parent appear above the sprites of it's children?

Link to comment
Share on other sites

  • 2 weeks later...

From the phaser examples:

 

// Items are rendered in the depth order in which they are added to the Group

 

I don't know of any way to get around this.

 

You could either make the second sprite not be a child of that class, or have it be another instance of the class that is added before the first sprite.

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 months later...

Did you ever find a solution for this? .bringToTop() seems to bring the sprite + its children to the top relative to sprites not in that sprite group.

 

I'm using the .addChild() method of a sprite to keep them grouped together, rather than an actual group which doesn't seem to be quite what I'm after.

Link to comment
Share on other sites

After mucking about with this I settled on a sort of hacky workaround. Basically you declare the sprite without specifying the key for the image to use, so basically starting with an empty sprite. Add the child sprites you want to appear behind the main sprite, and then add the main sprite as a child last. Does the trick for me.

Link to comment
Share on other sites

  • 8 months later...
  • 1 year later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...