Back to project page Gloomy-Dungeons-3D.
The source code is released under:
MIT License
If you think the Android project Gloomy-Dungeons-3D listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package zame.game.views; /*from w ww. java 2 s .co m*/ import android.content.Context; import android.util.AttributeSet; import android.view.KeyEvent; import android.view.MotionEvent; import zame.game.ZameGame; public class ZameGameView extends zame.libs.GLSurfaceView21 { private ZameGame game; public ZameGameView(Context context, AttributeSet attrs) { super(context, attrs); setFocusable(true); requestFocus(); setFocusableInTouchMode(true); } public void setGame(ZameGame game) { this.game = game; setRenderer(game); } @Override public void onWindowFocusChanged(boolean hasWindowFocus) { if (game != null) { if (hasWindowFocus) { game.resume(); } else { game.pause(); } } } public static boolean canUseKey(int keyCode) { return ( (keyCode != KeyEvent.KEYCODE_BACK) && (keyCode != KeyEvent.KEYCODE_HOME) && (keyCode != KeyEvent.KEYCODE_MENU) && (keyCode != KeyEvent.KEYCODE_ENDCALL) ); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (canUseKey(keyCode) && (game != null)) { if (game.handleKeyDown(keyCode)) { return true; } } return super.onKeyDown(keyCode, event); } @Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (canUseKey(keyCode) && (game != null)) { if (game.handleKeyUp(keyCode)) { return true; } } return super.onKeyUp(keyCode, event); } @Override public boolean onTouchEvent(MotionEvent event) { if (game != null) { game.handleTouchEvent(event); } try { Thread.sleep(16); } catch (InterruptedException e) { } return true; } @Override public boolean onTrackballEvent(MotionEvent event) { if (game != null) { game.handleTrackballEvent(event); } return true; } }