playh5 Posted April 4, 2014 Share Posted April 4, 2014 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 codethis.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 More sharing options...
Martiny Posted April 4, 2014 Share Posted April 4, 2014 Shouldn't you use Phaser.Timer.SECOND instead of 1000? I don't know much about it, but that is the only thing I can think of for now. Link to comment Share on other sites More sharing options...
playh5 Posted April 4, 2014 Author Share Posted April 4, 2014 At first I used that too, and it's the same problem. Link to comment Share on other sites More sharing options...
Taleforge Posted April 4, 2014 Share Posted April 4, 2014 I cant confirm this error using Samsung Galaxy S4. Just to be sure you mean the timer at the top between the health-bars!? For me its the same tick on the Desktop and the mobile (I use Chrome on both devices). Link to comment Share on other sites More sharing options...
playh5 Posted April 4, 2014 Author Share Posted April 4, 2014 Wow! glad it work perfectly in your s4. I tested on my xperia lt26i and Asus memo pad. The timer ran fast. Hope Rich could give a comment for this. Link to comment Share on other sites More sharing options...
jflowers45 Posted April 4, 2014 Share Posted April 4, 2014 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. http://viget.com/extend/time-based-animationhttp://codetheory.in/time-based-animations-in-html5-games-why-and-how-to-implement-them/ like your game BTW! Link to comment Share on other sites More sharing options...
playh5 Posted April 5, 2014 Author Share Posted April 5, 2014 Thanks for the explanation about the time and cpu lag jFlowers, I'll try the update function Link to comment Share on other sites More sharing options...
Recommended Posts