Game Development Reference
In-Depth Information
JNIEXPORT jint JNICALL Java_quake_jni_Natives_keyRelease
(JNIEnv * env, jclass cls, jint key)
{
Key_Event((int)key, 0);
return key;
}
Next, you'll tackle touch handling.
Handling Touch Events
Touch events work in a way similar to key events. Listing 6-8 demonstrates how to cascade
XY delta touch coordinates to the native engine to control the pitch and yaw of the character
in 3D space.
Listing 6-8. Translating XY Touch Coordinates into Pitch and Yaw
// in QuakeView.java
private float moveX = 0f;
private float moveY = 0f;
public boolean onTouchEvent(final MotionEvent e) {
final int action = e.getAction();
queueEvent(new Runnable() {
public void run() {
if (action == MotionEvent.ACTION_DOWN) {
// QuakeKeyEvents.onKeyDown(KeyEvent.KEYCODE_ENTER, null);
moveX = e.getX();
moveY = e.getY();
}
else if (action == MotionEvent.ACTION_UP) {
moveX = moveY = 0;
}
else if (action == MotionEvent.ACTION_MOVE) {
final float dx = e.getX() - moveX;
final float dy = e.getY() - moveY;
final float DX = Math.abs(dx);
final float DY = Math.abs(dy);
if (DX < 30 && DY < 30) {
return;
}
Natives.mouseMove((int) dx, (int) dy);
}
}
});
return true;
}
 
Search WWH ::




Custom Search