Jump to content

Attach sprite behind sprite?


Kiwiboy
 Share

Recommended Posts

Hi,

 

so I'm working on a game and I'm wondering if there's an easy way to code the following. I have an animal sprite, with body, collision, gravity, animations etc all implemented and working like I want. But now I want to add a tail sprite to the animal.

 

animal.addChild(tail) works like I want only it puts the tail in front and I can't seem to change that. So I'm wondering if there's a simple way like to do the same thing only put it behind the first sprite.

 

I know you can do stuff with groups, maybe I have to here, but then I have to change how everything interacts with the animal don't I? P.S. it's a cat. :)

 

Cheers

Link to comment
Share on other sites

Found this same problem some time before. Tried manually sorting the children array myself, but it seems that the parent ObjectContainer (Sprite in this case) will always be behind.
 

One simple solution that worked for me was to add the sprite I wanted to be on the back to a Group being under the rest of the objects, and update its position to match the parent on every update call.

Link to comment
Share on other sites

The solution I use is to create a container sprite (just a sprite with null for the key) then apply a body to it and resize it appropriately using body.setSize, then use container.addChild to attach the parts of your sprite in the order you need them, ensuring they don't have bodies themselves.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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