Taking a closer look with zoom cameras
AndEngine's BoundCamera
and Camera
objects do not support zooming in and out by default. If we would like to allow zooming of the camera, we can create a ZoomCamera
object which extends the BoundCamera
class. This object includes all of the functionality of its inherited classes, including creating camera bounds.
How to do it...
The ZoomCamera
object, similar to BoundCamera
, requires no additional parameters to be defined while creating the camera:
ZoomCamera mCamera = new ZoomCamera(0, 0, WIDTH, HEIGHT);
How it works…
In order to apply zoom effects to the camera, we can call the setZoomFactor(factor)
method, where factor
is the magnification we would like to apply to our Scene
object. Zooming in and out can be achieved with the following code:
// Divide the camera width/height by 1.5x (Zoom in) mCamera.setZoomFactor(1.5f); // Divide the camera width and height by 0.5x (Zoom out) mCamera.setZoomFactor(0.5f);
When handling the camera's zoom factor, we...