Search code examples
androidbox2dandenginegame-physics

Making forces to work same on Different Resolutions


I am facing multi resolution issue in box 2d.

First I needed to make bodies multi resolution, I solved it by scaling the vertices by scale factor.

Now I need to make the forces to act same of all different resolution devices, Is there any way to do it?

I want to make this line of code to work same on all devices

obj.getBody().applyForce( new Vector2(0, -220), obj.getBody().getWorldCenter());

Here 220 is the factor should I make it multi res by this formula

public float getY(float value) {
    y = (value / 540) * 100;
    return (y / 100) * CAMERA_HEIGHT;
}

Here 540 is the base resolution. I call getY(220) to make it multi resolution.

When I use this code on resolution 540*960 it works fine but when I change the device say of resolution 720*1280 the game acts real slow. Can any one help me with this issue? I tried to explain my question. Thanks in ADVANCE.


Solution

  • You scale the graphics by setting your camera to something other than the device's pixel count.

    Andengine will do everything else for the scaling.

    All you need to get from the device is the ratio of x to y pixels.

    In the example I have at this link, I just set one variable and everything is scaled to that.http://pastebin.com/WWGFvTVS

    So you just decide what initial scale you want to work on, and do your Box2D stuff without worrying about scale. You just have to scale the Camera that is looking at the scene.

    I'm saying the same thing as these other guys, you just don't seem to be understanding them.