rgk Posted August 26, 2015 Share Posted August 26, 2015 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 More sharing options...
vazzp Posted August 28, 2015 Share Posted August 28, 2015 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 More sharing options...
rgk Posted September 4, 2015 Author Share Posted September 4, 2015 That actually works flawlessly, only thing I notice that might be overkill is setting the timer each time but thank you very much for the response. Link to comment Share on other sites More sharing options...
Recommended Posts