我在玩一个游戏,我想要一个柜台。它从200开始,然后从1开始,减少约0。它是我的代码:
public class GameView extends View{
private int count = 200;
private TimeCountThread timeCountThread;
public GameView(Context context, AttributeSet attrs) {
super(context, attrs);
timeCountThread = new TimeCountThread();
timeCountThread.start();
}
protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
paint.setColor(Color.WHITE);
canvas.drawText("Time :"+count, 10, 35, paint);
}
public class TimeCountThread extends Thread{
public void run(){
while(count > 0){
try {
sleep(1000);
count--;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public boolean onTouchEvent(MotionEvent event){
if(event.getAction()==MotionEvent.ACTION_DOWN){
int x1=(int) event.getX();
int y1=(int) event.getY();
Toast.makeText(getContext(), "x1 = "+x1+", y1 ="+y1,1).show();
}
return true;
}
}
Why the counter don t activity .Please help me? Thanks