OpenAphid-Engine

JavaScript&OpenGL ES Powered 2D Game Engine for Native iOS/Android Apps

How to Handle Touch Events in Flip Animation

Updates at 2012-12-12: Please checkout FlipView for an improved solution.

This short post explains how to handle touch events for the flip animation introduced in our previous post.

The full source codes of the demo application are available at Github:

https://github.com/openaphid/android-flip/tree/master/Legacy/Demo-Touch/

A pre-built APK file is also present for your Android devices:

https://github.com/openaphid/android-flip/blob/master/Legacy/Demo-Touch/APK/Flip-Touch.apk

Updated at 2012-08-17: Fixed the broken links to the project and the APK file.

The new demo app adds two new features compared to the previous one:

  • Supports flipping over between two views. FlipCards.java takes screenshots of the front and back views, which are used to construct the textures for the translucent GLSurfaceView. The flip animation is rendered by four instances of Card. Please refer to the draw(GL10 gl) method for more details.

  • Flip angle can be controlled by touch events. Angle is calculated according to the relative movement of touches. The logic can be found in the handleTouchEvent(MotionEvent event) method.

Future Enhancements

The demo app is just a prove of concept. It can be enhanced to be a component for general scenarios:

  • To support a Adapter as its data source to load views dynamically and lazily.

  • To implement similar APIs like ListView

  • To support other fancy effects that can be implemented in OpenGL ES.

But I’m sorry that I’ll be in a long trip with my family. Both android-flip and OpenAphid-Engine will not be updated until I come back. You can still reach me via email if you have any questions.

Comments