Building a HUD class to display control buttons and text
The HUD, as usual, will display all the on-screen information to the player. The HUD for this game (as we saw at the start of the chapter) is a bit more advanced and as well as regular features like the score and player's lives it also has the control buttons.
The control buttons are basically slightly transparent rectangles drawn on the screen. It will be important that when we detect the player's touches we determine accurately if a touch happened within one of these rectangles as well as which rectangle.
An entire class dedicated to these rectangles (as well as the usual text) seems like a good idea.
Furthermore, as we did with the Snake
and the Apple
classes in the previous project, the HUD
class will also be responsible for drawing itself when requested. Add a new package private class called HUD
and add the member variables and the constructor shown next:
import android.graphics.Canvas; import android.graphics.Color...