Game Development Reference
In-Depth Information
}
return false;
}
/**
* Key Released
*/
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
// Ignore MENU
if (keyCode == KeyEvent.KEYCODE_MENU)
return false;
try {
int sym = ScanCodes.keySymToScancode(keyCode);
Natives.keyRelease(sym);
} catch (UnsatisfiedLinkError e) {
System.err.println(e.toString());
}
return false;
}
/**
* Touch event
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
try {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// Fire on tap R-CTL
Natives.keyPress(ScanCodes.sc_Control);
} else if (event.getAction() == MotionEvent.ACTION_UP) {
Natives.keyRelease(ScanCodes.sc_Control);
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
// Motion event
}
return true;
} catch (UnsatisfiedLinkError e) {
// Should not happen!
Log.e(TAG, e.toString());
return false;
}
}
Creating the Game Loop
In this section, we look at how the game starts within the main activity (see Listing 6-5). The startGame
function performs the following steps:
Search WWH ::




Custom Search