Reputation: 77
I'm creating a game using LibGDX, the game it was finished, but when I started testing on different Android smartphones, I discovered that the game runs with no problem on the old Android versios like 2.. but when I tested it on the latest Android versions like 3 or 4, the box has dragging problems, and I dont really know how to fix it, cos it works well on some old Android versions...
Here's the code I use to drag the box on the InputHandler file:
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
miBox.onClick( screenX, screenY );
return false;
}
On the box handler file:
public void onClick(int screenX, int screenY) {
if (position.y < (originalY-100)){
position.x=screenX;
}
}
I was wondering if it could be a problem on the manifest file or something related with it... what do you think?.
If you know what I could be doing wrong, i would like you to comment! Thanks
Upvotes: 1
Views: 116
Reputation: 5495
The problem is not with the android version, is with the android screen size, you need to translate your screen coords to world coords.
Vector3 touchPos = new Vector3(screenX, screenY, 0);
camera.unproject(touchPos);
float x=touchPos.x, y=touchPost.y;
And now use x and y.
And don't forget that initializing objects every frame is not a good ideea, i would declare my vector3 somewhere and just set its x y and z (z being 0 always ) coords every frame.
Upvotes: 1