Hi guys I am building my game right now and trying to get some text to disappear after a few seconds. I am using Phaser and I am not to sure how to do this.
Currently I have:
Asteroid.time.events.remove(Phaser.Timer.SECOND - 3, this.startInstructions3, this);
My text appears on the page fine:
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);
}
Then when I go back to my levelIncrease
function i have :
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);
},
My question is, is it like -3 or is there a set thing you can do in Phaser like duration or something like that? I can't seem to find anything about it.
Thanks.
There's actually an official example that covers this scenario for you.
Your Asteroid.time.events.remove()
would actually remove an event, not add a removal event. For example, if you had an event that looped and wanted to remove that event, you would use time.events.remove
.
So you want to add an event that triggers after three seconds, so something like the following, instead of your Asteroid.time.events.remove
line:
Asteroid.time.events.add(Phaser.Timer.SECOND - 3, this.nameOfFunctionToHideText, this);
Where nameOfFunctionToHideText
(or whatever new function you create) would be the one that would remove the text.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.