Pinch-zoom camera functionality
AndEngine includes a small list of "detector" classes which can be used in combination with scene touch events. This topic is going to cover the use of the PinchZoomDetector
class in order to allow zooming of the camera by pressing two fingers on the display, moving them closer or further apart to adjust the zoom factor.
Getting started…
Please refer to the class named ApplyingPinchToZoom
in the code bundle.
How to do it…
Follow these steps for a walkthrough on setting up the pinch-to-zoom functionality.
The first thing we must do is implement the appropriate listeners into our class. Since we'll be working with touch events, we'll need to include the
IOnSceneTouchListener
interface. Additionally, we'll need to implement theIPinchZoomDetectorListener
interface to handle changes in the camera's zoom factor pending touch events:public class ApplyingPinchToZoom extends BaseGameActivity implements IOnSceneTouchListener, IPinchZoomDetectorListener {
In the
onCreateScene...