Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Physics Pixel-To-Meter

edited September 2013 in Questions Posts: 18

I'm trying to port one of my games to libgdx to make it playable with android devices. One problem I've encountered is the differences in using box2d: It seems like Codea is doing pixel-to-meter calculations in the background, I''ve found the pixel-to-meter ratio (32) in the manual, but somehow box2d is still behaving differently in libgdx than in codea.. there some more documentation on how exactly box-to-world/world-to-box calculation is done in Codea?


  • Box2d just moves objects etc within it's coordinate system, if you just draw at those coordinates then it's pixels to meters. If you want to get a different ratio then don't use the coordinates raw to pixels, adjust them yourself.


    Ellipse(circleBody.x/ratio, circleBody.y/ratio) or some such.

  • JohnJohn Admin Mod
    Posts: 464

    Codea just multiplies and divides by the ratio so that 32 pixels on the screen = 1 meter within box2d. You can change the ratio but you'd want to do this before creating any physics objects. One thing that Codea does that might not be obvious is that it compensates for interpolation when using coordinate conversions so that you end up with smooth movement no matter how you derive coordinates. How is it behaving differently from libgdx?

  • Yes! Defining the PTM Ratio before making the body is the most important thing. That's what I got wrong.

Sign In or Register to comment.