tanvirgeek
tanvirgeek

Reputation: 163

How can i combine orthographic camera X, Y and the input processor screenX, screenY?

I made a two rectangles to divide screen in two regions. Touching in each region do two different things. my camera is like below:

camera = new OrthographicCamera();
camera.setToOrtho(false, 800, 480);

My rectangles are like these:

leftRectangle.set(0, 0, 400, 400);
rightRectangle.set(400, 0, 400, 400);

So what i thought i am doing with camera that, I made my phone screen resolution 800px 400px, whatever my actual resolution, it does not matter, coz i am using camera to do so. But inputprocessor screenX and screenY is returning X,Y according to my phones actual resolution. So I am not getting the camera made touching X,Y. So I am geeting wrong touching value.

How can i make this touching X,Y value same as the camera made resolution?

Upvotes: 1

Views: 121

Answers (1)

noone
noone

Reputation: 19776

Use Camera.unproject() to do that.

Vector3 screenCoords = new Vector3(screenX, screenY, 1);
Vector3 cameraCoords = camera.uproject(screenCoords);
float cameraX = cameraCoords.x;
float cameraY = cameraCoords.y;

Upvotes: 1

Related Questions