Sign in to follow this  
Kiwiboy

Attach sprite behind sprite?

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

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.