Jump to content

Having trouble destroying Sprites


Recommended Posts



I'm having trouble destroying sprites and I don't really understand why it's not working.


I have an object, let's call it Block. Block has a sprite property that gets added at construction like so:

this.sprite = this.game.add.sprite(this.x, this.y, 'blocks', this.color);


At a certain point, I have two arrays that reference Block:

square[0] = Block;

destroy[0] = Block;


At some point in the update function, I need to destroy Block's sprite, so this happens:

square[0] = null;
What I'd expect is that in the next Update cycle, I should be seeing:
destroy[0].sprite == null
However all I'm seeing is:
destroy[0].sprite == b.Sprite;
With it's alive and visible properties just set to false.
My worry is that if I were to now set:
destroy[0] = null;
what will happen to that sprite object? Should I set it to null first or will it get cleaned up automatically? Also, how is destroy() different from kill() if it doesn't null out the reference?
Link to comment
Share on other sites


  • Recently Browsing   0 members

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