badboy_tqj
badboy_tqj

Reputation: 300

in Libgdx, how to calculate the b2body's point in screen size

picture

In libgdx I set:

mCam = new OrthographicCamera(100, 100 * h / w);
// mCam.position.set(50, 50, 0);
mCam.position.set(24, 150, 0);
mCam.zoom = 0.5f;
mCam.update();

and print a body.x = 4, y = 153

and how to calculate the point into screen point

Upvotes: 1

Views: 246

Answers (1)

noone
noone

Reputation: 19776

What you want should probably be Camera.project(...)

It should work this way:

Vector3 worldCoordinates = new Vector3(body.getPosition().x, body.getPosition().y, 0);
Vector3 screenCoordinates = mCam.project(worldCoordinates);

Upvotes: 1

Related Questions