如何让文本在几秒后消失
how to get text to disappear after few seconds
大家好,我现在正在构建我的游戏,并试图让一些文本在几秒钟后消失。我正在使用 Phaser,但我不确定该怎么做。
目前我有:
Asteroid.time.events.remove(Phaser.Timer.SECOND - 3, this.startInstructions3, this);
我的文字在页面上显示正常:
if (!this.rockmodel.countLiving()) {
Asteroid.time.events.add(Phaser.Timer.SECOND * 3, this.levelIncrease, this);
var startInstructions3 = 'NEXT LEVEL! ';
this.gametext3 = Asteroid.add.text(Asteroid.world.centerX, Asteroid.world.centerY, startInstructions3, lifefont3.thefont3);
this.gametext3.align = 'center';
this.gametext3.anchor.set(0.5, 0.5);
}
然后当我回到我的 levelIncrease
函数时,我有:
if (this.rockcount < rocksincoming.max) {
this.rockcount += rocksincoming.astup;
}
Asteroid.time.events.remove(Phaser.Timer.SECOND * 3, this.startInstructions3, this);
this.randomrock();
},
endofgame: function () {
Asteroid.state.start(gameobjectstouse.menu);
},
我的问题是,它是像 -3 还是您可以在 Phaser 中做一些固定的事情,比如持续时间或类似的东西?我似乎找不到任何相关信息。
谢谢。
实际上 an official example 为您介绍了这种情况。
您的 Asteroid.time.events.remove()
实际上会删除一个事件,而不是添加一个删除事件。例如,如果您有一个循环事件并想删除该事件,您可以使用 time.events.remove
.
所以你想添加一个在三秒后触发的事件,所以像下面这样的东西,而不是你的 Asteroid.time.events.remove
行:
Asteroid.time.events.add(Phaser.Timer.SECOND - 3, this.nameOfFunctionToHideText, this);
其中 nameOfFunctionToHideText
(或您创建的任何新函数)将是删除文本的函数。
大家好,我现在正在构建我的游戏,并试图让一些文本在几秒钟后消失。我正在使用 Phaser,但我不确定该怎么做。
目前我有:
Asteroid.time.events.remove(Phaser.Timer.SECOND - 3, this.startInstructions3, this);
我的文字在页面上显示正常:
if (!this.rockmodel.countLiving()) {
Asteroid.time.events.add(Phaser.Timer.SECOND * 3, this.levelIncrease, this);
var startInstructions3 = 'NEXT LEVEL! ';
this.gametext3 = Asteroid.add.text(Asteroid.world.centerX, Asteroid.world.centerY, startInstructions3, lifefont3.thefont3);
this.gametext3.align = 'center';
this.gametext3.anchor.set(0.5, 0.5);
}
然后当我回到我的 levelIncrease
函数时,我有:
if (this.rockcount < rocksincoming.max) {
this.rockcount += rocksincoming.astup;
}
Asteroid.time.events.remove(Phaser.Timer.SECOND * 3, this.startInstructions3, this);
this.randomrock();
},
endofgame: function () {
Asteroid.state.start(gameobjectstouse.menu);
},
我的问题是,它是像 -3 还是您可以在 Phaser 中做一些固定的事情,比如持续时间或类似的东西?我似乎找不到任何相关信息。
谢谢。
实际上 an official example 为您介绍了这种情况。
您的 Asteroid.time.events.remove()
实际上会删除一个事件,而不是添加一个删除事件。例如,如果您有一个循环事件并想删除该事件,您可以使用 time.events.remove
.
所以你想添加一个在三秒后触发的事件,所以像下面这样的东西,而不是你的 Asteroid.time.events.remove
行:
Asteroid.time.events.add(Phaser.Timer.SECOND - 3, this.nameOfFunctionToHideText, this);
其中 nameOfFunctionToHideText
(或您创建的任何新函数)将是删除文本的函数。