Java View Game Development framework

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.