I have fixed timestep code in my main thread, it looks like this:
float oldTimeSinceStart = 0;
float accumulatedTime = 0;
float maxDeltaTime = 0.1f; // 10 FPS
float fixedTime = 0.016f; // 60 FPS
while(running)
{
float timeSinceStart = System.nanoTime();
float deltaTime = (timeSinceStart - oldTimeSinceStart) / 1000000000;
oldTimeSinceStart = timeSinceStart;
deltaTime = Math.min(deltaTime, maxDeltaTime);
accumulatedTime += deltaTime;
while (accumulatedTime >= fixedTime)
{
accumulatedTime -= fixedTime;
gamePanel.update();
}
gamePanel.draw(canvas);
}
I have objects on scene, which positions are updated as
position += speed;
And speed is calculated on app start as
speed = (screenWidth / 2) * fixedTime;
These codes should work well to get same objects speeds on all devices and also smooth visual. Speed works quite well, but visual appereance is bad. I'm getting periodical "lags" about each half second on my old Galaxy Ace and also on S III Mini. So it's like running smoothly - lag - running smoothly - lag...
Any ideas what could cause these lags?