如何让文本在几秒钟后消失

how to get text to disappear after few seconds

本文关键字:几秒 消失 文本      更新时间:2023-09-26

大家好,我现在正在构建我的游戏,并试图让一些文本在几秒钟后消失。我正在使用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的持续时间或类似的东西?我似乎找不到任何关于它的信息。

谢谢。

实际上有一个官方示例为您介绍了这个场景。

Asteroid.time.events.remove()实际上会删除一个事件,而不是添加一个删除事件。例如,如果您有一个循环的事件,并且希望删除该事件,则可以使用time.events.remove

因此,您希望添加一个在三秒后触发的事件,因此类似于以下内容,而不是您的Asteroid.time.events.remove行:

Asteroid.time.events.add(Phaser.Timer.SECOND - 3, this.nameOfFunctionToHideText, this);

其中nameOfFunctionToHideText(或您创建的任何新函数)将是删除文本的函数。