Scaling for multiple resolutions in Box2d and Android
I am developing a 开发者_如何学Cgame that uses box2d engine in android. I create the physics world by definitions coming out a xml defined for 320X480 resolution.
Now in box2d I have considered that 1 unit is 30 Pixels. The question is , is there any other option other than defining a separate xml for each resolution to scale this properly for all screens ?
I have tried to get screen density from Display metrics and adjust the scale that box2d uses but the physics world does not look the same.
Anybody ran into this situation and resolved it ?
Thanks in advance.
Define the world size from the display size converted into meters using your PTM_RATIO eg.
WindowManager w = getWindowManager();
Display d = w.getDefaultDisplay();
int width = d.getWidth();
int height = d.getHeight();
mWorldWidth = (float)(width / PTM_RATIO);
mWorldHeight = (float)(height / PTM_RATIO);
Then create your bounding shapes using the mWorldHeight and mWorldWidth values, that way you'll always be working to the scale of the available screen size.
You should find a way to rescale your drawing so that independent of resolution you would fit the same number of in-game units on the screen. Sadly I can't help you with the specifics as I don't know the android API.
精彩评论