PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

time synchronized movement

I'm wondering as to what the best way to synchronize animation/movement on PocketPC devices is.

On the PC, I usually determine the delta time between frames and then do something like:

pos += velocity * delta_time

Which works quite well but on PocketPC's floating point isn't always such a good idea although I've used the same technique there with good results and no slow downs. I tried doing the same thing with fixed point but it doesn't work well at all but that could have been a crappy implementation of it.

Another method I had seen is people limiting the frame rate to always get 30 fps but, I'm wondering how fool proof that is.

How did you guys out there implement this?
I almost use milliseconds (1/1024th of a second to be exact).

So if velocity is in units per second, and delta time is an integer representing (almost) milliseconds duration of the frame:

pos += (velocity * delta_time) >> 10;

Now I don't care about the .024 loss of precision per second, so I use actual milliseconds (1/1000th) for delta_time (GetTickCount()). If that is a problem for you (maybe due to video / audio timing or something that must be properly synchronized) then you can adjust delta_time just once each frame to represent 1/1024 of a second.

Also, each frame you need to check to see if delta_time is zero. If your game runs really fast, or is on fast hardware, you can have issues with that. If delta_time is zero I just sleep for a couple milliseconds and start the frame over. That will make a massive difference with battery life if your game is not using 100% of the CPU.

Dan East
Hmm that seems to make more sense than the way I was doing it!

I'm going to have to experiment some more!