Kiwiboy Posted October 27, 2014 Share Posted October 27, 2014 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 More sharing options...
mariogarranz Posted October 27, 2014 Share Posted October 27, 2014 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 More sharing options...
lewster32 Posted October 28, 2014 Share Posted October 28, 2014 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 More sharing options...
Recommended Posts