I'm trying to implement a zoom feature but I have a problem. I am zooming in and out a camera with a pinch gesture, I update the camera each time in the render, but my sprites keep their original position and don't change with the zoom in or zoom out.
The Libraries are from libgdx.
What am I missing?
private void zoomIn()
{
((OrthographicCamera)this.stage.getCamera()).zoom += .01;
}
public boolean pinch(Vector2 arg0, Vector2 arg1, Vector2 arg2, Vector2 arg3)
{
// TODO Auto-generated method stub
zoomIn();
return false;
}
public void render(float arg0)
{
this.gl.glClear(GL10.GL_DEPTH_BUFFER_BIT | GL10.GL_COLOR_BUFFER_BIT);
((OrthographicCamera)this.stage.getCamera()).update();
this.stage.draw();
}
public boolean touchDown(int arg0, int arg1, int arg2)
{
this.stage.toStageCoordinates(arg0, arg1, point);
Actor actor = this.stage.hit(point.x, point.y);
if(actor instanceof Group)
{
((LevelSelect)((Group) actor).getActors().get(0)).touched();
}
return true;
}
Zoom In
Zoom Out
Answer
My best guess is that your sprites reside in the same world space as the camera does while your hit boxes (collision rects) reside in screen space. Your world space sprites are affected by the camera's zoom but screen space collision boxes are not.
Your best shot it to quantify your collision boxes in world space like your sprites are instead of screen space and then you will not have this problem.
No comments:
Post a Comment