Building a Renderer class to handle the drawing
The Renderer
class will oversee controlling the drawing. As the project evolves it will have multiple types of class that it will trigger to draw themselves at the appropriate time. As a result, we will regularly add code to this class including adding extra parameters to method signatures.
For now, the Renderer
class only needs to control the drawing of the HUD and we will now code it accordingly.
Create a new package private class called Renderer
and add this code.
import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.view.SurfaceHolder; import android.view.SurfaceView; import java.util.ArrayList; class Renderer { private Canvas mCanvas; private SurfaceHolder mSurfaceHolder; private Paint mPaint; Renderer(SurfaceView sh){ mSurfaceHolder = sh.getHolder(); mPaint = new Paint(); } }
As you can see from the code you just added the Renderer
will hold the...