Create a new package private class and call it UIController
.
Note
As already stated, later in the project we will also have another InputObserver
based around the player spaceship game object, but we need to do a bit more theory in the next chapter before we can implement that.
Add some class imports, the implements InputObserver
code to the class declaration and add the constructor as highlighted next.
import android.graphics.Point; import android.graphics.Rect; import android.view.MotionEvent; import java.util.ArrayList; class UIController implements InputObserver { public UIController(GameEngineBroadcaster b){ b.addObserver(this); } }
All we need to do in the constructor is call the addObserver
method using the GameEngineBroadcaster
instance b
that was passed in as a parameter. A reference to this class will now be safely tucked away in the inputObservers ArrayList
.