I'm trying to calculate object speed from delta time, to get object reaching the same distance in same time on all devices.
What I did:
while(running) float timeSinceStart = System.nanoTime(); float deltaTime = (timeSinceStart - oldTimeSinceStart) / 1000000000; oldTimeSinceStart = timeSinceStart;
From that I'm getting deltaTime:
2.2789123E8 on my old Galaxy Ace S5830i
2.7855414E8 on my tablet A7600-F
And then I do this calculation:
float calculation = screenWidth/2 * deltaTime; //My game is in landscape mode int speed = Math.round(calculation); //speed represents pixels per update
Which should give speed that half of the screen is reached per 1 second, regardless on device updates (fps). It should be small number, about 10-20, but calculation results in
- 546 on Ace
- 1782 on tablet
What to do with that? As I said, if I set speed to fx. 11, it's reaching about half of the screen in my game on tablet. So why are these number's so large?
Ed: Ace width = 480, tablet width = 1280;