Jump to content

Question about destroying sprites and events


bapho
 Share

Recommended Posts

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:

  1. Group A
    1. Sprite 1
    2. Group 1
      1. Sprite I
      2. Sprite II
      3. Text I
    3. Sprite 2
    4. Group 2
      1. Sprite I
      2. 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

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

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...