Jump to content

Question about destroying sprites and events


Recommended Posts


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);


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

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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