WEB开发网
开发学院手机开发Android 开发 Android 开发中的游戏开发使用 View 还是 Surface... 阅读

Android 开发中的游戏开发使用 View 还是 SurfaceView

 2010-02-27 07:25:00 来源:WEB开发网   
核心提示:import android.view.SurfaceHolder;import android.view.SurfaceView;public class MySurfaceView extends SurfaceView implementsSurfaceHolder.Callback {private Conte

import android.view.SurfaceHolder;

import android.view.SurfaceView;

public class MySurfaceView extends SurfaceView implements

SurfaceHolder.Callback {

private Context mContext;

private SurfaceHolder mHolder;

public TouchScreenAdjusterSurfaceView(Context context,) {

super(context);

mContext = context;

mHolder = TouchScreenAdjusterSurfaceView.this.getHolder();

mHolder.addCallback(TouchScreenAdjusterSurfaceView.this);

this.setFocusableInTouchMode(true); // to make sure that we can get

// touch events and key events,and

// "setFocusable()" to make sure we

// can get key events

}

@Override

public void surfaceChanged(SurfaceHolder holder, int format, int width,

int height) {

// TODO Auto-generated method stub

}

@Override

public void surfaceCreated(SurfaceHolder holder) {

//now you can get the Canvas and draw something here

}

@Override

public void surfaceDestroyed(SurfaceHolder holder) {

// TODO Auto-generated method stub

}

public void drawMyShape(PointPostion ps) {

mCanvas = mHolder.lockCanvas();

// draw anything you like

mHolder.unlockCanvasAndPost(mCanvas);

}

}

上一页  1 2 3 4 

Tags:Android 开发 游戏

编辑录入:coldstar [复制链接] [打 印]
赞助商链接