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?

Thanks in advance.

  • 3
    \$\begingroup\$ Why are you tying your physics calculations to screen resolution? \$\endgroup\$
    – ssb
    Jun 7 '14 at 12:30
  • 3
    \$\begingroup\$ The physics simulation should never scale. Scale your rendering instead. \$\endgroup\$
    – bummzack
    Jun 7 '14 at 13:04
  • 2
    \$\begingroup\$ You have to define your units. For example, choose meters. The character will be 1m tall, the gravity is -10m, and on. \$\endgroup\$ Jun 7 '14 at 13:28
  • \$\begingroup\$ 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. \$\endgroup\$
    – user46877
    Jun 7 '14 at 14:13
  • \$\begingroup\$ 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. \$\endgroup\$ 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;


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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.