# Game speed on different devices isn't same

I have an app, in which I have constant int speed = 5; On each update, the game object (player) is moving 5px ahead. Problem is, that I can't handle that on different devices - older devices is having fx. 20fps (so 20 updates per second), and other one have 60fps. Then, my object is moving faster or slower, than it should.

I tried some screen width divisions, but didn't managed to work it.

I also tried to stick to some FPS (25) and skip frames if necessary. But on my tablet and phone, it just run on its own; it works like there isn't any frame skip code at all.

• Try using delta time, or the time passed between this frame and the previous one. For example, speed = 5 m/s then position += speed * deltaTime (in seconds). – EvilTak Nov 21 '15 at 18:17
• To add to what the other commenter said, you should research "fixed time step". Here is a link for you gafferongames.com/game-physics/fix-your-timestep – bazola Nov 21 '15 at 18:20
• Remember objects in the real world don't have "pixels moved per frame" they have velocities. And a velocity is a movement per time. Everything should be expressed as something per second. Then calculate what that means in terms of something per frame in the frame itself when you know how much of a second that particular frame is worth – Richard Tingle Nov 21 '15 at 21:16

position.x = velocity * deltaTime;