bapho Posted June 8, 2018 Share Posted June 8, 2018 Hi, I'd like to confirm something about the .destroy() function on groups and sprites. What happens to the attached events to sprites that act as buttons when you destroy them in the following scenarios? Scenario A: Group 1 -> Sprite (with inputEnabled) -> has onInputDown, onInputUp, etc... events - I then do [Group 1].destroy() Scenario B: Sprite (with inputEnabled) -> has onInputDown, onInputUp, etc... events - I then do [Sprite (with inputEnabled)].destroy() Will the events linger around, like having an invisible clickable button? Or will they be cleanly removed as if I did something like [Sprite (with inputEnabled)].events.(onInputDown/onInputUp, etc...).removeAll()? I'm doing some menu system right now that has something like: Group A Sprite 1 Group 1 Sprite I Sprite II Text I Sprite 2 Group 2 Sprite I Sprite II Well, it's not that complex, but what I'd like to know is when destroying this entire menu, do I need to recursively go down the tree, remove all those input events from sprites that are buttons, destroy each of the children before moving up one level and the do the same thing? Does everything get destroyed completely and cleanly if I destroy [Group A]? Does destroying [Group 2] or [Group 1] cleanly destroy anything inside these groups? Thanks guys! Link to comment Share on other sites More sharing options...
samme Posted June 8, 2018 Share Posted June 8, 2018 https://photonstorm.github.io/phaser-ce/Phaser.Group.html#destroy group.destroy() destroys all children and their input handlers. Link to comment Share on other sites More sharing options...
bapho Posted June 8, 2018 Author Share Posted June 8, 2018 Ok! Thanks for clearing that up! That also goes for destroying Sprites? In case I have a defined function that will be called like this: funcs = {}; funcs['helloworld'] = function() { console.log('hello world'); } button.events.onInputDown(funcs['helloworld']), this); button.events.onInputDown.removeAll(); or doing a group.destroy() where this button is a child of. will funcs['helloworld'] be nulled, or left alone? Link to comment Share on other sites More sharing options...
bapho Posted June 8, 2018 Author Share Posted June 8, 2018 BTW, if I do: [Group A].destroy() I can see the [Group A] is still an object in the console, but it's children are not visible already. What can I do with this [Group A]? Do I just overwrite the variable that holds reference to it with a null, 0, or '' to get rid of it? Link to comment Share on other sites More sharing options...
Recommended Posts