Scaling bodies for multiple screen resolutions

Hi,

I'd like for my game to support all the ios devices. This would mean, 480x320/1024x768/568x320 and their corresponding retina displays. The retina displays aren't a problem because they're 2 pixels per point but I have to deal with multiple devices. I'm currently working on a 480x320 configuration with a 32 points per meter conversion for Box2D. Are there any guidelines on how I can scale the bodies in the game?

1. If I just increase all the body sizes, the forces change and the interaction is different from device to device. I'd like to keep it consistent across devices.
2. Can I fix an A m x B m size in Box2D and just scale up or scale down the pixels per meter?
aksraj wrote:Hi,

I'd like for my game to support all the ios devices. This would mean, 480x320/1024x768/568x320 and their corresponding retina displays. The retina displays aren't a problem because they're 2 pixels per point but I have to deal with multiple devices. I'm currently working on a 480x320 configuration with a 32 points per meter conversion for Box2D. Are there any guidelines on how I can scale the bodies in the game?

1. If I just increase all the body sizes, the forces change and the interaction is different from device to device. I'd like to keep it consistent across devices.
2. Can I fix an A m x B m size in Box2D and just scale up or scale down the pixels per meter?


Go for option 2, change your pixels to meter scaling ratio. Works a treat.
If I go by that suggestion -

My game is going to be a vertical game. So, 1024x768(ipad) would be the lowest common denominator. If I were to scale this for the iphone, I would only end up using 425/480 for the regular iphone and 850/1136 for the newer iphones. This would mean I would have quite some wastage of vertical space. How do you recommend I deal with that?
I see a lot of these questions and they seem to cause people a real headache for some reason I can't quite figure out. The most important thing is as you have already noticed, you absolutely must not go changing the physics scene around just because a different sized screen is present. Here is how I would recommend you approach it:

1. Design your physics scene first. At this stage, forget about screens altogether. Pretend you have never heard of a pixel, or a point, or a phone or a tablet or whatever.

2. Decide on a dimension (vertical or horizontal) to use as the basis for scaling calculations. This is the dimension for which the displayed area of the world will be the same across different screen aspect ratios. I usually use the vertical dimension for this, because my game is played in landscape. This means that the left and right edges of the view will show more of the scene for devices with a wide aspect ratio, and less for narrower aspect ratios. I think most people are used to this, since we have varying width movie screens and TVs, and it's commonly the same way movies are shot. For example in this image, the amount of view displayed in the vertical dimension is the same for all aspect ratios:
Image

3. Ask yourself, how much of the physics scene do you want to display for that dimension. For example if you went with vertical dimension as your basis, and you're making a platform game where the player is 1 unit high, and he jumps between levels of platforms that are about 2-3m meters high, and you want the view zoom to show a few levels of platforms, you might decide that 10m vertically of the physics scene is a good span (ie. your player being 1m high would take up 1/10th of the screen vertically). Another thing to consider at this point is the minimum view area for the smallest aspect ratio screen. From the image above we can see that some devices can see more at the left/right sides than others, so you would need to set your basis view span to make sure anything important will be inside the view area of the smallest aspect. To my knowledge, 4:3 (iPad) is the smallest aspect among mobile devices.

4. At runtime, check how many pixels the device you are running on has in your chosen basis dimension. For example, original iPhone will have 320 for the vertical dimension in my landscape example.

5. Divide 4. by 3. to get your ppm value. In the example above, showing a 10m span of the physics world over 320 pixels would be 320/10 = 32 as you currently have. On iPad, it would be 768/10 = 76.8

You can adjust the ppm every frame to zoom in and out, if your game needs that.
Thank you for that. That was very useful.

Original thread: https://box2d.org/forum/viewtopic.php?t=9827