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.SurfaceHolder;
import android.view.SurfaceView;
import android.view.SurfaceHolder.Callback;
public class MySurfaceView extends SurfaceView implements Callback, Runnable {
public SurfaceHolder sfh;
public Canvas canvas;
public Paint paint;
public static int SC_W , SC_H ;
public MySurfaceView(Context context, AttributeSet attrs) {
super(context, attrs);
sfh = getHolder();
sfh.addCallback(this); //binding surface to surface 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(); 
相关新闻>>
- 发表评论
-
- 最新评论 更多>>