Search code examples
androidlibgdxbox2dandroid-hardware

Different Box2D body speeds on different devices


My problem is documented in this: Video

Background speed and animations are running at the same speed while items, who are thrown by that black guy, move slower on the white device... Well yeah, white phone is older, but that is not the problem, i think, because i've tested my app on a phone with almost the same hardware as the black phone's and it had the same issue. Could anyone help me understand why this is happening...?

my step - world.step(1 / 60f , 6, 2);. And dimensions are divided by PPM of 100.

Thank you!


Solution

  • Libgdx always runs the fastest the device can handle (except in desktop in which you can cap it to 60 times per second).

    Hardware is not always the difference. Android devices have a Frames per Second cap, for example my Galaxy Ace has a FPS cap of 90. And some even newer and more powerful devices may have 60 or even 50. So your app would update faster in my galaxy ace than in any of those other devices.

    You can use this technique to cap it yourself:

    Have this two fields.-

    public static final float FPSCAP = 1/60F;
    private float accumulator = 0;
    

    And in your render method.-

    accumulator+=delta;
    while(accumulator>FPSCAP){
       world.step(FPSCAP, 6, 2);
       accumulator-=FPSCAP;
    }