Coding the camera

This class is completely new to this project. The key to understanding it is to remember that all our game objects have sizes and positions in virtual meters. All the movement and collision detection will be done using these virtual meters. Here is the key-key point:

Tip

These virtual meters currently bare no relation to the pixels on the screen. The Camera class will know the screen's resolution and translate these virtual meters into pixel coordinates. Not all game objects will be on the screen every frame. In fact, most game objects will not be visible, most frames.

Add a new class called Camera and add the following member variables and the constructor.

import android.graphics.PointF; import android.graphics.Rect; class Camera ...

Get Learning Java by Building Android Games - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.