小编ale*_*nia的帖子

在Phaser中摧毁精灵

我在Phaser中摧毁精灵时遇到了麻烦.

我有一个JavaScript对象,我们称之为Block.Block有一个sprite属性,设置如下:

this.sprite = this.game.add.sprite(this.x, this.y, 'blocks', this.color);
Run Code Online (Sandbox Code Playgroud)

在我的代码中的某个点,Block由两个不同的数组引用:

square[0] = Block;
destroy[0] = Block;
Run Code Online (Sandbox Code Playgroud)

在某个Update()循环中,我需要销毁精灵,所以我使用以下代码:

square[0].sprite.destroy(true); //Destroy the sprite.
square[0] = null; //Remove the reference.
Run Code Online (Sandbox Code Playgroud)

在下一个Update()循环中,当我查看destroy [0]时,我希望看到:

destroy[0].sprite: null
Run Code Online (Sandbox Code Playgroud)

然而,我所看到的是:

destroy[0].sprite: b.Sprite
Run Code Online (Sandbox Code Playgroud)

属性只是默认并设置为false.我担心的是,如果我现在将destroy [0]设置为null,那个sprite对象会发生什么?

它会浮动还是自动清理?我应该先以某种方式破坏Block对象吗?另外,如果destroy()没有使引用为空,那么它与kill()有什么不同?

任何有关此事的想法将不胜感激.

javascript html5 sprite phaser-framework

17
推荐指数
1
解决办法
1万
查看次数

标签 统计

html5 ×1

javascript ×1

phaser-framework ×1

sprite ×1