Java Game Development Engine view is more suitable for passive-triggered games, can not be used in the game of that battle
Game01activity.java here is the activity of the call
Package Cn.sun.syspro;import Android.app.activity;import Android.os.bundle;import android.view.window;import Android.view.windowmanager;public class Game01activity extends activity { /** called when the activity is first create d. */ @Override public void OnCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); Setcontentview (r.layout.main); Hidden Freeze this.requestwindowfeature (window.feature_no_title); This.getwindow () . SetFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_ fullscreen); Setcontentview (New Myview (This));} }
Myview.java
Package Cn.sun.syspro;import Android. R.style;import Android.content.context;import Android.graphics.canvas;import Android.graphics.color;import Android.graphics.paint;import Android.view.keyevent;import Android.view.motionevent;import Android.view.View; public class Myview extends view{/** * Overrides parent class constructor * @param context */private int x = 200,y = 200;public Myview (Context Conte XT) {super (context); setfocusable (true);//TODO auto-generated constructor stub}/** * Rewrite drawing function */@Overrideprotected void OnDraw (canvas canvas) {//Create a brush paint paint = new paint ();//Set the brush's color Paint.setcolor (color.black);//Draw Text Canvas.drawrgb ( 224, Canvas.drawtext ("Hello Sun", this.x,this.y, Paint); Super.ondraw (canvas); /** * Overrides the press event */@Overridepublic boolean onKeyDown (int keycode,keyevent event) {if (KeyCode = = event. KEYCODE_DPAD_UP) {this.y-=2;} else if (keycode = = event. Keycode_dpad_down) {this.y+=2;} else if (keycode = = event. Keycode_dpad_left) {this.x-=2;} else if (keycode = = event. Keycode_dpad_right) {this.x+=2;} Invalidate (); reTurn Super.onkeydown (keycode, event);} /** * Rewrite key to bounce event */@Overridepublic boolean onKeyUp (int keycode,keyevent event) {if (KeyCode = = event. KEYCODE_DPAD_UP) {this.y-=2;} else if (keycode = = event. Keycode_dpad_down) {this.y+=2;} else if (keycode = = event. Keycode_dpad_left) {this.x-=2;} else if (keycode = = event. Keycode_dpad_right) {this.x+=2;} Invalidate (); return Super.onkeyup (KeyCode, event);} /** * Override the Touchscreen event function */@Overridepublic boolean ontouchevent (Motionevent event) {int t_x = (int) event.getx (); int t_y = (int) even T.gety (); if (event.getaction () = = Motionevent.action_down) {this.x = T_x;this.y = t_y;} else if (event.getaction () = = Motionevent.action_move) {this.x = T_x;this.y = t_y;} else if (event.getaction () = = motionevent.action_up) {this.x = T_x;this.y = t_y;} Invalidate (); return super.ontouchevent (event);}}
Java View Game Development framework