当前位置:操作系统 > 安卓/Android >>

android-->游戏框架

 

说明一下:一直以来都是做j2me平台的游戏开发的。这次要转到android ,想想肯定思想是想通的,因此也就写了此文

 

 废话不多说直接上源码

 

 

 

package Sur.Face.Pro;

 

import android.content.Context;

import android.graphics.Canvas;

import android.graphics.Color;

import android.graphics.Paint;

import android.util.AttributeSet;

import android.view.Su易做图ceHolder;

import android.view.Su易做图ceView;

import android.view.Su易做图ceHolder.Callback;

 

public class MySu易做图ceView extends Su易做图ceView implements Callback, Runnable {

       public Su易做图ceHolder sfh;

       public Canvas canvas;

       public Paint paint;

         public static int SC_W  , SC_H ;

       public MySu易做图ceView(Context context, AttributeSet attrs) {

              super(context, attrs);

              sfh = getHolder();

              sfh.addCallback(this); //binding su易做图ce to su易做图ce view

              paint = new Paint();

              paint.setAntiAlias(true);

                  paint.setColor(Color.RED);

                  this.setKeepScreenOn(true);// keep screen light

       }

 

       public void run() {

              int count = 0;

              while (count++ < 20) {

                     logic();

                     paint();

                     sleep();

              }

       }

 

       private void logic() {

              // do your logic

       }

 

       public void sleep() {

              try {

                     Thread.sleep(100);

              } catch (InterruptedException e) {

                     e.printStackTrace();

              }

       }

 

       public void paint() {

              canvas = sfh.lockCanvas();                    // 获得类画布其他的操作就跟j2me是相同的了         // do your paint

 

              sfh.unlockCanvasAndPost(canvas);

 

       }

 

       public void su易做图ceCreated(Su易做图ceHolder holder) {

               SC_W = getWidth() ;

               SC_H = getHeight() ;

               new Thread(this).start();

 

       }

 

       public void su易做图ceChanged(Su易做图ceHolder holder, int format, int width,

                     int height) {

 

       }

 

       public void su易做图ceDestroyed(Su易做图ceHolder holder) {

 

       }

 

}

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,