# Resolution independent physics

I'm making a game like Doodlejump but don't know how to make the physics scale on multiple resolutions. I also can't find anything related to this on Google. Right now I'm scaling the game using letterboxing and tested scaling the jump height with this code:

gravity = graphics.getHeight() * 0.001f;
jumpVel = graphics.getHeight() * -0.04f;

...

velY += gravity;
y += velY;


But if I test this on my smartphone or emulator with different resolutions, I always get a slightly different jump height. I know that Farseer is resolution independent. How can I replicate this in my game?

• Why are you tying your physics calculations to screen resolution?
– ssb
Jun 7 '14 at 12:30
• The physics simulation should never scale. Scale your rendering instead. Jun 7 '14 at 13:04
• You have to define your units. For example, choose meters. The character will be 1m tall, the gravity is -10m, and on. Jun 7 '14 at 13:28
• That is what I'm searching for, but I don't know how to implement this and I also can't find any code examples on this. Sorry if this is something really simple but I can't think clearly right know. Jun 7 '14 at 14:13
• Are you factoring time into your equations? It doesn't look like you are. Not doing so would cause different jump heights depending on the frame rate. Jun 14 '14 at 21:48

You don't scale your physics. Your physics should be based in an arbitrary coordinate system, completely independent of the device.

Then when you do your drawing, you translate your "physical" location to a screen location based on the screen resolution. You need to calculate the scaling amount based on the screen resolution.

For example, if you define your arbitrary world size as 1200 "units" wide, then on a device with a 1920 pixel wide screen, your view scale is: 1920/1200 = 1.6

So for example, gravity and jump velocity would simply be:

gravity = 0.001f;
jumpVel = -0.04f;

viewScale=graphics.getWidth()/WORLD_WIDTH;


Then when you draw your object, you'd use:

screenX=worldX*viewScale;
screenY=worldY*viewScale;