Coding a Multitouch UI controller and making it a listener
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 ...
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.