Ninjadoodle Posted January 25, 2018 Share Posted January 25, 2018 Hi @enpu / others who might be able to help I'm trying to remove all the sprites inside a container when clicking, and I'm using this code ... for (var i=0; i<game.scene.mg.children.length; i++) { game.scene.mg.children[i].remove(); } Only some sprites get removed tho. Any idea what I'm doing wrong? Thanks in advance! Quote Link to comment Share on other sites More sharing options...
enpu Posted January 25, 2018 Share Posted January 25, 2018 https://www.panda2.io/docs/api/Container Look at Container methods, there is removeAll And the reason why your code is skipping some sprites is that your for loop is going from start to end. You should do it from end to start: for (var i = game.scene.mg.children.length - 1; i >= 0; i--) { game.scene.mg.children[i].remove(); } Ninjadoodle 1 Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted January 25, 2018 Author Share Posted January 25, 2018 @enpu lol, so simple! Honestly tho, how good is this engine!! Thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.