我在Phaser中销毁Sprites时遇到了问题。
我有一个JavaScript对象,叫做Block。Block具有Sprite属性,可以像下面这样设置:
this.sprite = this.game.add.sprite(this.x, this.y, 'blocks', this.color);
在我的代码的某个点上,Block 被两个不同的数组引用:
square[0] = Block;
destroy[0] = Block;
在某个Update()周期中,我需要销毁精灵,因此我使用以下代码:
square[0].sprite.destroy(true); //Destroy the sprite.
square[0] = null; //Remove the reference.
在下一次 Update() 循环中,当我查看 destroy[0] 时,我希望看到的是:destroy[0].sprite: null
然而我正在看到的是:
destroy[0].sprite: b.Sprite
使用刚刚默认设置为false的属性,我担心如果我现在将destroy [0]设置为null,那个精灵对象会发生什么?
它会漂浮还是会自动清理? 我应该以某种方式首先销毁Block对象吗? 此外,如果destroy()不会使引用为空,则它与kill()有何不同?
对此的任何想法都将不胜感激。