# How to use the zoom gesture in libgdx?

I found the example code for the GestureListener class, but I don't understand the zoom method:

private float initialScale = 1;

public boolean zoom (float originalDistance, float currentDistance) {
float ratio = originalDistance / currentDistance; //I get this
camera.zoom = initialScale * ratio; //This doesn't make sense to me because it seems like every time you pinch to zoom, it resets to the original zoom which is 1. So basically it wouldn't 'save' the zoom right?
System.out.println(camera.zoom); //Prints the camera zoom
return false;
}


Am I not interpreting this right?

• Shouldn't it be camera.zoom ×= ratio; ? – bornander Oct 5 '15 at 15:36
• I think this interface and the GestureDetector class is not very well thought through. I'm having the same problem, and I'm now trying to figure out a good solution. – Adam Toth May 29 '16 at 16:19
• I think the interface would need a zoomStart(float distance) and a zoomStop(float initialDistance, float finalDistance) method – Adam Toth May 29 '16 at 16:23

Each time you put your fingers on the screen the originalDistance / currentDistance will result in the value 1.
To solve this issue you should store the current zoom factor at the start of the zoom and multiply this with the new calculated ratio. So: on touchDown take the current zoom: initialScale = Camara.zoom;.
initialScale looks like a constant used to scale everything in the game.
zoom function calculates originalDistance / currentDistance value, applies it to Camera and prints it out.