O'Reilly logo

Android NDK Game Development Cookbook by Viktor Latypov, Sergey Kosarevsky

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required