alvatar Posted March 31, 2014 Share Posted March 31, 2014 Hi! I'm trying to figure out how to detach a sprite from a Group. Currently you add it with the group as a two-step process:1) Create the Sprite2) Add it to the group: group.add(sprite) But if I want to detach it from the group, so I can handle it individually, I have no other option than "destroy", which removes the Sprite.Setting the parent to null doesn't work either.The objective is that when a specific condition is met, the tween that is applied to all elements in the group as a whole doesn't apply to this particular sprite. Thank you! Link to comment Share on other sites More sharing options...
Heppell08 Posted March 31, 2014 Share Posted March 31, 2014 Can you not use:sprite.group.remove(sprite); Link to comment Share on other sites More sharing options...
alvatar Posted March 31, 2014 Author Share Posted March 31, 2014 That's actually removing the Sprite and it doesn't render any longer.Plus, is giving me this error:Uncaught TypeError: Cannot read property 'visible' of undefined Link to comment Share on other sites More sharing options...
Heppell08 Posted March 31, 2014 Share Posted March 31, 2014 Because it is killing the sprite on removal. You need to find a way to create it again at the time needed. It really depends on the set up you're trying to achieve but this post may also help you... http://www.html5gamedevs.com/topic/2020-remove-element-from-group/ Link to comment Share on other sites More sharing options...
rich Posted April 1, 2014 Share Posted April 1, 2014 Move it to another Group:group.remove(sprite);group.add(sprite);Remember that World is a Group. So you can do world.add(sprite) quite happily, which will keep it on the display list and rendering. Removing a child from a Group does not destroy or kill it, but it WILL stop rendering if you don't add it back onto the display list somewhere. Link to comment Share on other sites More sharing options...
alvatar Posted April 1, 2014 Author Share Posted April 1, 2014 Great! That was what I was looking for. I wasn't aware that world was a group. Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts