Jump to content

elapsed.time and FPS observations and solution for iPad2


MoreK
 Share

Recommended Posts

iPad2 (& Safari) seem to drop my game's frame rate from 60ps to 30fps max. 30fps is still ok, so I tried to resolve the move/speed issue by using delta time between frames, at the beginning of every update routine:

 

var deltaTime = game.time.elapsed;

 

...and applying deltaTime to x/y movements.

 

This just caused image & sprite movements to double their speed in iPad. Game tweens seemed to suffer the same problem. However P2 physics seem to work ok in all devices.

 

After searching and testing, I found a solution for delta time:

 

var deltaTime = game.time.physicsElapsed;

 

And for tweens, setting this parameter did the trick:

 

Tween.frameBased = true;

 

...although duration seem to be still in milliseconds, not in frames, as the documentation states.

 

I'm wondering where Phaser.Time.elapsed is needed, when Phaser.Time.physicsElapsed does the trick so much better?!

Link to comment
Share on other sites

You shouldn't have to do this yourself, Phaser is already built to use deltaT. So your objects will move at the same speed, regardless of the FPS. What version of Phaser are you using? This has been implemented quite a while ago...

 

Wow, I've been hasty, reading older comment and recommendations. You are absolutely right. I took away my delta time logic and image/sprite movement works as expected no matter FPS.

 

However, I still see the issue in a chained tween. It shows 3-2-1-GO countdown at the beginning of the game, using PNG images. Other tweens in the game seem to work ok, but this one runs double speed in 30fps. "frameBased" parameter seem to fix the issue, so not a big deal, but clearly something I don't understand. Or maybe a bug? Here's the code:

 

        this.ctp_twA = this.add.tween(this.ctp_3).to({alpha: 1, width: 206, height: 132}, 1000, Phaser.Easing.Linear.None);        //this.ctp_twA.frameBased = true;        this.ctp_twA.onComplete.add(this.removeImg, this, this.ctp_3);        this.ctp_twB = this.add.tween(this.ctp_2).to({alpha: 1, width: 206, height: 132}, 1000, Phaser.Easing.Linear.None);        //this.ctp_twB.frameBased = true;        this.ctp_twB.onComplete.add(this.removeImg, this, this.ctp_2);        this.ctp_twC = this.add.tween(this.ctp_1).to({alpha: 1, width: 206, height: 132}, 1000, Phaser.Easing.Linear.None);        //this.ctp_twC.frameBased = true;        this.ctp_twC.onComplete.add(this.removeImgAndGo, this, this.ctp_1);        this.ctp_twGO = this.add.tween(this.ctp_go).to({alpha: 1, width: 206, height: 132}, 1000, Phaser.Easing.Linear.None);        //this.ctp_twGO.frameBased = true;        this.ctp_twGO.onComplete.add(this.removeImg, this, this.ctp_go);        this.ctp_twA.chain(this.ctp_twB, this.ctp_twC, this.ctp_twGO);        this.ctp_twA.start();
Link to comment
Share on other sites

Hmmm there was indeed an issue with tweens (I remember at least a post dealing with this)... But I think what you are doing is fine. If you want the tween to play at the same speed whatever the FPS, you should set frameBased = false. You could check what the default value is (false would make sense, but I'm not sure).

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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