Handling touches
To get started with screen interaction, add the OnTouchEvent
function to the LiveDrawingView
class as follows:
override fun onTouchEvent( motionEvent: MotionEvent): Boolean { return true }
This is an overridden function, and it is called by Android every time the user interacts with the screen. Look at the one and only parameter of onTouchEvent
.
It turns out that motionEvent
has a whole bunch of data tucked away inside it, and this data contains the details of the touch that just occurred. The operating system sent it to us because it knows we will probably need some of it.
Note that I said some of it. The MotionEvent
class is quite extensive; it contains within it dozens of functions and properties.
For now, all we need to know is that the screen responds at the precise moment that the player's finger moves, touches the screen, or is removed.
Some of the variables and functions contained within motionEvent
that we will use include the following:
- The
action
property...