892848153 发表于 2013-1-30 04:06:32

android 游戏开发框架

Activity类:必要属性 
各种surfaceView
 
各种动画线程
 
boolean isSound    //是否播放声音标志
 
各种声音    (mediaPlayer或者soundpool)
 
handler   //根据收到的mssage切换surfaceView或者更新控件
 
 
Entity类: 必要的属性(记录位置,宽高等)  
 
doDraw(Cancas cancas){}  //绘制自己
 
touchEvent(int x, int y){}   //出发事件

contains(int x, int y)                //碰撞检测
 
nextFrame()                            //切换动画的下一帧,有这个方法后在换帧线程中只要不断的调用  这个方法就可以了。
 
SurfaceView类:必要属性   1:activity   2:换帧线程   3:Entitys
public 构造函数(Activity activity)  //用来控制声音或者通过handler向activity发送message

doDraw(Canvas canvas)       //调用entity的doDraw
 
touchEvent(MotionEvent event)                         //调用Entity的touchEnvent
 
public void surfaceCreated(SurfaceHolder holder)  // 启动换帧线程
 
     public void surfaceDestroyed(SurfaceHolder holder)// 停止换帧线程
 
物理引擎线程类: 构造函数将要控制的对象传进来(一般是entity)  注意:"一直"在调整entity的状态才需                                       要物理引擎
 
属性:int sleepSpan 休眠时间
 
 boolean flag 循环标志
 
                 计算下一状态的信息,并改变控制对象的属性
 
换帧线程类: 构造函数传入SurfaceView类
 
属性:int sleepSpan                     //休眠时间
 
boolean flag                      //循环标志
 
        SurfaceVie  surfaceView  //调用其onDraw()方法
 
SurfaceHolder surfaceHolder    //用与得到Canvas
 
public 构造函数(surfaceView, surfaceHolder)
 
          主要调用SurfaceView的doDraw方法,注意同步 surfaceHolder
 
动画线程类:若播放完动画切换surfaceView则              (放完动画用handler向activity发送消息)
 
                     int sleepSpan = 200;//睡眠的毫秒数
 
                 private boolean flag = true;
 
                 int status = 0;
 
                 Activity activity;           //activity的引用
 
                 public 构造函数(Activity activity){
 
                      this.activity =activity;
 
                     }
 
                  public void setFlag(boolean flag){
 
                     this.flag = flag;
 
                      }
 
          public void run() {//重写的run方法
 
          while(flag){
 
  switch(status){ case 0: case 1:.........................}
 
KeyThread(键盘监听线程):
 
在activity的onKeyUp(),onKeyDown()函数中只设置了一个键盘状态位action用于记录什么键被按下,在
 
keyThread中获取action并作出响应。
 
页: [1]
查看完整版本: android 游戏开发框架