CADisplayLink Timestamp acts strange on device

1.1k Views Asked by At

For my game loop and certain animations I want to know the time interval that has passed since the last call of my render: method.

For this I use the CADisplayLink and grab the current timestamp and subtract the timestamp of the last call. This should give me the correct time interval between two frames/calls.

When running the app in the simulator, I get all sorts of different values for the interval, which seem fine. If I run the app on the iPad however, I only get two different values for the interval: 0.000 and 0.125. Most of the time these two values alternate.

Here is the code I use to determine the interval.

// Time calculations (for animations and stuff)
_lastCallTime = _currentCallTime;
_currentCallTime = [displayLink timestamp];
float timeInterval = _currentCallTime - _lastCallTime;

NSLog(@"Time since last call: %f", timeInterval);

This code gets executed every time the render method gets called.

Is this some restriction of the iPad, that it won't give me accurate results for my interval?

1

There are 1 best solutions below

0
On BEST ANSWER

The timestamp is a double. Change any variable that saves or uses it as a float to NSTimeInterval. When you print it use %f (which is really %lf as C promotes floats to doubles when passed as parameters).