Game Development Reference
In-Depth Information
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 will send a right control ( KEY_RCTL ) to the native layer, which will result in
the weapon being fired.
Native Callback Handlers
The native callback handlers are implemented by the main activity ( DoomClient.java ) via the
Natives.EventListener interface. This allows the activity to listen for native callbacks. The handlers are
divided in the following categories:
Graphics initialization : This handler receives information when the native
graphics have been initialized. It receives the width and height of the video buffer.
Image update : This handler receives video buffer updates and fires multiple times
per second.
Message update : This handler receives string messages from the native rendering
engine.
Fatal errors : This handler will fire whenever an unrecoverable error occurs.
Sound and music requests : A series of handlers handle audio.
Graphics Initialization Handler
The graphics initialization handler is critical and must be the first to fire before the game can start. It
receives the width and height of the video buffer, which are used to create the Android bitmap that
Search WWH ::




Custom Search