我做了一个游戏,你应该撞到痣。我postDelayed
用来让痣每隔几秒钟出现和消失一次。
问题是当我触摸痣时,它会变成挤压的痣图片并且痣消失(应该如此),但是当痣回到屏幕时,它会出现错误的图片(挤压的)。
STAGE 视图类
private Runnable everyThreeSeconds = new Runnable() {
public void run() {
moleView.getMole().moveMole();
isPop = !isPop;
postDelayed(everyThreeSeconds, (3000)) ;
}
};
public AllViews(Context context) {
super(context);
test = new Paint();
first = new First_Stage();
isPop=false;
post(everyThreeSeconds);
}
public void setViews(StageView mainView, MoleView moleView,
PointsView pointsView, TimerView timerView,ClubView clubView)
{
this.mainView = mainView;
this.moleView = moleView;
this.pointsView = pointsView;
this.timerView = timerView;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
mainView.onDraw(canvas);
pointsView.onDraw(canvas);
timerView.onDraw(canvas);
clubPic=BitmapFactory.decodeResource(getResources(), R.drawable.clubdown);
canvas.drawBitmap(clubPic, this.x-39,this.y-20, null);
if (isPop){
moleView.onDraw(canvas);
}
invalidate();
}
鼹鼠类
public MoleView(Context context, Mole mole) {
super(context);
this.mole=mole;
}
@Override
protected void onDraw(Canvas canvas) {
if (!bool){
molePic=BitmapFactory.decodeResource(getResources(), R.drawable.nest_full_mole);
canvas.drawBitmap(molePic, mole.getX(), mole.getY(), null);
}else {
molePic=BitmapFactory.decodeResource(getResources(), R.drawable.pow);
canvas.drawBitmap(molePic, mole.getX(), mole.getY(), null);
}
}