Game Development Reference
In-Depth Information
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Ignore menu key
if (keyCode == KeyEvent.KEYCODE_MENU) {
return false;
}
int sym = DoomTools.keyCodeToKeySym(keyCode);
try {
Natives.keyEvent(Natives.EV_KEYDOWN, sym);
}
catch (UnsatisfiedLinkError e) {
// Should not happen
Log.e(TAG, e.toString());
}
return false;
}
public boolean onTouchEvent(MotionEvent event)
{
try {
if ( event.getAction() == MotionEvent.ACTION_DOWN) {
// Fire on tap R-CTL
Natives.keyEvent(Natives.EV_KEYDOWN, DoomTools.KEY_RCTL);
}
else if ( event.getAction() == MotionEvent.ACTION_UP) {
Natives.keyEvent(Natives.EV_KEYUP, DoomTools.KEY_RCTL);
}
else if ( event.getAction() == MotionEvent.ACTION_MOVE) {
// Motion event
}
return true;
}
catch (UnsatisfiedLinkError e) {
// Should not happen!
Log.e(TAG, e.toString());
return false;
}
}
For touch events, Android provides three actions: ACTION_DOWN , ACTION_UP , and ACTION_MOVE ,
when the user is pressing, releasing, and dragging fingers in the device screen, respectively.
When a finger press or release occurs, Doom sends a right control ( KEY_RCTL ) to the native
layer, which will result in the weapon being fired.
Search WWH ::




Custom Search