Limiting the camera area with the bound camera
The BoundCamera
object allows us to define specific bounds on the camera's area, limiting the distance the camera can travel on both the x and y axis. This camera is useful in situations where the camera may follow a player, but still not exceed the level bounds if the user travels close to a wall.
How to do it...
The BoundCamera
object creation requires the same parameters as a regular Camera
object:
BoundCamera mCamera = new BoundCamera(0, 0, WIDTH, HEIGHT);
How it works...
The BoundCamera
object extends the ordinary Camera
object, giving us all of the original functionality of a camera as described in the Introducing the camera object recipe, which is given in this chapter. In fact, unless we configure a bounded area on the BoundCamera
object, we are ideally working with a basic Camera
object.
Before our camera will apply restrictions to its available movement area, we must define the available area in which the camera is free to move:
// WIDTH...