Jump to content

Setting labels every second?


rgk
 Share

Recommended Posts

Hi, I'm trying to optimize my game and I have a few items that show fps and ping and update the timer data, I want to only update these labels once every second with a timer but what I try doesn't seem to work:

For example for the timer:
        this.timerEvent2 = this.turnTimer.repeat(Phaser.Timer.SECOND, 30, this.turnTimerText.setText(this.formatTime(Math.round((this.timerEvent1.delay - this.turnTimer.ms) / 1000))), this);

Or for fps:
        this.timerEvent3 = this.turnTimer.loop(Phaser.Timer.SECOND, this.fpsText.setText(this.time.fps), this);

Format Time just turns it into the 00:00 format. Any ideas?

Link to comment
Share on other sites

Hi there! :)

 

I hope I read your question correctly but in my game I did something like an fps counter that only updates every second like this:

var onFPSUpdate = function(fpsTextObj) {    fpsTextObj.text = "FPS: " + game.time.fps;    var ms = 1000;    fpsTextObj.updateEvent  = this.game.time.events.add(ms, function(){ onFPSUpdate(fpsTextObj); }, this);};...//somewhere in your code like in .create()onFPSUpdate(this.fpsText); //this will start the timer...

If you want you can then later remove the timer with

 game.time.events.remove(fpsText.updateEvent); //remove the timer
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...