Handling asynchronous multi-touch input
In the previous chapter we learned how to handle multi-touch events on Android. However, our simple example has one serious issue. Android touch events are sent asynchronously and can interfere with the game logic. As such, we need to create a queue to process events in a controllable way.
Getting ready
Check out the Processing multi-touch events on Android recipe from Chapter 7, Cross-platform UI and Input System, before proceeding.
How to do it…
In the previous chapter we invoked the touch handler directly from an asynchronous JNI callback:
Java_com_packtpub_ndkcookbook_game1_Game1Activity_SendMotion( JNIEnv * env, jobject obj, int PointerID, int x, int y, bool Pressed, int Flag) { LVector2 Pos = LVector2( (float)x / (float)g_Width, (float)y / (float)g_Height ); GestureHandler_SendMotion( PointerID, (eMotionFlag)Flag, Pos,Pressed ); }
This time, we have to store all the events in a queue rather then processing them...