This is probably a simple question, but I noticed world:step() is supposed to use a consistent variable (1/60 usually). I'm curious what is the best way to take into account some devices may run at 60 fps, while others may run a bit slower. To keep this in mind, I figured time-based code would be best, so regardless of your fps everything happens within the same amount of time. This made me wonder how I should approach this and all I can think of is keeping track of how many steps have been made and keep track of total time run and then make as many steps as needed each frame to keep up related to the time.
Does that sound about right, or is there a better way to handle this? Thanks!
Comments
You can get absolute time using os.timer()
And then inside onEnterFrame event, event object provides a deltaTime property, which I think was the time since last enterframe event call. Thus you can now how much time has passed.
I think that GTween library uses same approach internally, you can check it's source code.
function onEnterFrame(e)
cloud_world:step(e.deltaTime, 8, 3)
moveCamera()
end
Will see how it goes. I am a bit skeptic about dynamic step, red somewhere /long ago/ that dynamic steps cause simulation instability but i could be wrong.
Would definitely be curious to see how that works out!
I wonder if GTween keeps the remainder of time not used to add in to the next step though. Since theoretically you would slowly fall behind if you only stepped the amount of times required for the delta time.
but how said by @plamen box2d steps should be fixed (from box2d docs)
...
www.tntengine.com
Likes: MoKaLux