4
\$\begingroup\$

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 In

Zoom Out Zoom Out

\$\endgroup\$
12
  • 1
    \$\begingroup\$ First make sure that the camera is actually changing. Then make sure that you are applying the camera to the sprite. \$\endgroup\$ Mar 30, 2012 at 23:07
  • \$\begingroup\$ Also, these types of questions are hard to answer with no context, code or screenshots. \$\endgroup\$ Mar 30, 2012 at 23:08
  • 1
    \$\begingroup\$ what is your graphic API, what is your platform, what is the language? is the camera even moving \$\endgroup\$
    – gardian06
    Mar 30, 2012 at 23:15
  • \$\begingroup\$ The zoom is actually working, because the image is zooming in and zooming out, but the position doesnt change, ill put the code \$\endgroup\$
    – Rudy_TM
    Mar 30, 2012 at 23:21
  • 1
    \$\begingroup\$ let us continue this discussion in chat \$\endgroup\$ Mar 31, 2012 at 0:21

1 Answer 1

2
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .