Implementing an on-screen joypad
It is time to make use of the multi-touch facilities and emulate a gaming console-like interface on an Android device touch screen.
Getting ready
Learn how to handle multi-touch input from recipes Processing multi-touch events on Android and Processing multi-touch events on Windows before proceeding with this recipe.
How to do it...
We implement a custom multi-touch event handler, which keeps track of all the touch points. The joystick is rendered as a full-screen bitmap shown on the left-hand side. When the user touches the screen, we use the touch coordinates to fetch the pixel color from the mask on the right-hand side of the figure. Then, we find the internal button corresponding to the color and change its Pressed
state. The following figure shows the joypad visual representation and the color mask:
Single button of our virtual joystick is determined by its color in the mask and the index in the buttons table:
struct sBitmapButton { vec4 FColour; int FIndex...