Jump to content

Is there a problem with phaser time


mapacarta
 Share

Recommended Posts

I experienced some problems with the phaser time(delta value mostly) when developing a game with lots of images on the screen. The delta value on the update function always has values around 16.6 (which means game has close to 60fps I guess). But since my game has lots of images, some frames take longer to execute so I tried to fix the movements by multiplying them with delta*60/1000 (when the delta is around 16.6 this value is nearly one so no fix is applied). Because delta value is always  around16.6, this didn't help me. So I calculate the delta time between frames with new Date().getTime() and by using this new value movements became much better. (Btw, my game doesn't have any physics in it so I move the objects with classic x+=speed type of way)

Here are the values phaser delta and getTime() produces: (phaser delta is on the left always 16.6 as you can see):

image.png.6077dde3b2a13b397ad56ebd371bc75b.png

 

I have experienced another weird issue in my another game which may also seem time related, I have a real simple game and nearly for all movements it uses tweens. When I test the game on my android device it starts pretty slow for the first 10-15 seconds. At the start there are 2 tweens which normaly should last something like 0.5 seconds but it took seconds to complete. After the first 10-15 seconds the game runs perfectly. But the first 10-15 seconds are quite important for my game.

So is it possible that there is a problem with the phaser internal time?  I don't know how tweens work but if they are using the same value with update method's delta, this may be the reason. 

Link to comment
Share on other sites

Phaser smooths out the delta time (see source) so that the gameplay is better. That's what causes the desync with real time.

If you need precise timing, you need to run your own clock. Keep in mind internal things like tweens will still use Phaser's clock. If that's an issue, either tween manually or hack Phaser to pass unsmoothed deltaTime.

The issue you see on the android device could be cause by JIT/startup causing slower performance at the beginning, which results in big delta time, which Phaser in turns lowers into sensible values. So a second passes, but Phaser only simulated half a second.

Also keep in mind that your fix approach won't really work well on devices with different frame rates. It's not always 60 fps. I recommend reading Fix Your Timestep and if you plan on having custom physics read Integration Basics (`x += velocity * dt` is ok, but if `velocity` depends on delta too, better read it).

Link to comment
Share on other sites

Thanks for the explanation, I didn't know phaser smooths out the delta time but that make sense when I think about it. Otherwise with a low fps, tweens would go crazy.  I will see what I can do to make the game run faster at the beginning.

About the physics, I already use x+=velocity*dt.  The velocity doesn't depend on delta. I typed x+=speed just to express that I didn't use physics engine.  Velocity depend on delta can cause really weird behaviours I guess :D 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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