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 classes that it will trigger to draw at the appropriate time. As a result, we will regularly add code to this class, including adding extra parameters to some of the 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 class called Renderer
and edit it to match 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...