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. ...
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.