Coding the UIController class
This class will have the same purpose as the class of the same name did in the previous project. It will also look very similar too.
Add a new class called UIController
and add the member variables, constructor and addObserver
method.
import android.graphics.Point; import android.graphics.Rect; import android.view.MotionEvent; import java.util.ArrayList; class UIController implements InputObserver { private float mThird; private boolean initialPress = false; UIController(GameEngineBroadcaster b, Point size) { // Add as an observer addObserver(b); mThird = size.x / 3; } void addObserver(GameEngineBroadcaster b) { b.addObserver(this); } }
The float mThird
variable will help us to divide the screen up vertically into thirds. The player will then be able to tap a portion of the screen to choose the level that they want to play. The initialPress
Boolean is used in a workaround to avoid a bug/glitch...