I'm having trouble destroying Sprites in Phaser.
I have a JavaScript object, let's call it Block. Block has a sprite property, that gets set like so:
this.sprite = this.game.add.sprite(this.x, this.y, 'blocks', this.color);
At a certain point in my code, Block is referenced by two different arrays:
square[0] = Block;
destroy[0] = Block;
On a certain Update() cycle, I need to destroy the sprite, so I'm using the following code:
square[0].sprite.destroy(true); //Destroy the sprite.
square[0] = null; //Remove the reference.
On the next Update() cycle, when I look at destroy[0], I would expect to see:
destroy[0].sprite: null
However what I'm seeing is:
destroy[0].sprite: b.Sprite
With the properties just defaulted and set to false. My worry is, if I were to now set destroy[0] to null, what will happen to that sprite object?
Will it just float around or will it get cleaned up automatically? Should I be destroying the Block object first in some way? Also, if destroy() is not nulling the reference, how is it different from kill()?
Any thoughts on the matter will be greatly appreciated.