Game Development Reference
In-Depth Information
int action = event.getAction();
if ( action == MotionEvent.ACTION_DOWN ) {
startX = event.x;
startY = event.y;
}
else if ( action == MotionEvent.ACTION_UP ) {
startX = startY = 0;
}
else if ( action == MotionEvent.ACTION_MOVE)
{
final float dx = event.x - startX;
final float dy = event.y - startY;
// decide to move or look
mouseLook(dx , dy );
//mouseMove (dx, dy);
}
return true;
}
// C implementation of int mouseLook(int deltaX, int deltaY)
JNIEXPORT jint JNICALL Java_Natives_mouseMove
(JNIEnv * env, jclass cls, jint dx, jint dy)
{
LOGD("Mouse Move %d, %d", dx, dy);
}
// C implementation of int mouseLook(int deltaX, int deltaY)
JNIEXPORT jint JNICALL Java_Natives_mouseLook
(JNIEnv * env, jclass cls, jint dx, jint dy)
{
LOGD("Mouse Look %d, %d", dx, dy);
}
In the previous section you looked at single touch events, which may not be adequate for
some types of games, such as first-person shooters where the player needs to move and
aim at the same time. The next section can help. Multi-touch is a technique that expands
on the touch API to provide more fingers you can use around your game for more complex
interactions.
Multi-touch Tricks
The multi-touch capabilities of Android are an extension of MotionEvent . With these
capabilities, you have all the information you need to implement a multi-touch scheme. For
example, let's assume that you have a game where sweeping a finger on the left side moves
a character forward or sideways in 3D space, and sweeping on the right side looks around.
Using the Android MotionEvent , you can easily implement such a scheme. Consider three
sample classes, MultiTouchGesture , MultiTouchScreen , and TestActivity , all of which are
discussed in the following sections.
 
Search WWH ::




Custom Search