下面是主要代码:
public class GameSurfaceview extends SurfaceView implements
SurfaceHolder.Callback {
........................................... public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
int x = getIndex(event.getX());
int y = getIndex(event.getY());
Canvas canvas=holder.lockCanvas();
canvas.drawBitmap(blackchess, x,y,paint);
holder.unlockCanvasAndPost(canvas);
} return super.onTouchEvent(event);
}
...............................
}
点击屏幕时总是会黑屏 当再次点击时才会 回复正常 然后再点击 又会黑屏............
解决方案 »
Canvas canvas=holder.lockCanvas();
canvas.drawBitmap(blackchess, x,y,paint);
holder.unlockCanvasAndPost(canvas);
把画图抽取个draw 方法,放到线程中,你的是每点一次刷一次屏幕,如果放到线程中就不停的刷,就不会这样了!