我做了一个游戏,你应该撞击痣。我使用postDelayed
使痣出现并每隔几秒就消失。
问题是,当我触摸痣时,它会变成挤压的痣图像并且痣消失(应该如此),但是当鼹鼠回到屏幕时,它会出现错误的图像(被挤压)一个)。
论坛观看课程
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();
}
Mole View Class
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);
}
}
答案 0 :(得分:0)
刚刚添加到if条件中的else返回true返回false并且它正常工作
@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);
}else{
moleView.setBool(false);
}
invalidate();