Jump to content

My First Phaser games timer ticks fast in mobile


Recommended Posts

Hi, this is my first phaser game MathBoxing If you play it in pc browser the counter works perfectly. But in mobile the counter ticks very fast.


this is my code

this.game.time.events.loop(1000,this.updateCounter,this);updateCounter:function(){	if(gameState == "PLAY"){	        counter -= counterDec;//where counterDec = 1;		if(counter <=0 ){			counter = 10;			opponentSprite.animations.play('box',24,false);			playerHealth.scale.x -= 0.1;			this.checkPlayerHealth();		}		timeText.content = counter;	}},

Any help would be appreciated. Thanks!



Link to comment
Share on other sites

Pretty sure when you create a timer the way you're doing, there is the capability for it be 'off' by small amounts that grow over time if the CPU lags.  lets say it's off by 0.05 seconds the first time - then the next time it's off by 0.01 - now you're off by a total of .06.  This adds up over time.  This is more likely to happen on a mobile device where CPU is limited.


If 'tight' timing is critical for your game, you might be better off writing some of this logic yourself.  Instead of setting a timer that runs every second, you'd note the start time, and in the game's "update" loop (the update function in your state, which is pretty much an enterFrame event) you'll compare the current time to the time start, and if it's been 1000ms or more, kick off whatever has to happen - in your event, that's gonna be updating the "seconds" at the top of your display and checking if the game is over.


I'm not doing a great job explaining it, but reading up on "time based animation" vs "frame based animation" might help.



like your game BTW!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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