的答案 - 赛车条件布尔不改变
所以这是游戏我做产生的障碍,每个障碍熄灭屏幕它消除了障碍,增加了高分时间的类。这工作正常,但布尔(plusScore)在预期时不会更改为true。
public void update() {
//
if(obstacles.get(obstacles.size() - 1).getRectangle().top >= Constants.SCREEN_HEIGHT) {
int xStart = (int)(Math.random()*(Constants.SCREEN_WIDTH - playerGap));
obstacles.add(0, new Obstacle(obstacleHeight, color, xStart, obstacles.get(0).getRectangle().top - obstacleHeight - obstacleGap, playerGap));
obstacles.remove(obstacles.size() - 1);
score += 10;
plusScore = true; //Problem here
tempTime = (int)System.currentTimeMillis();
}
if (tempTime + 5 <= System.currentTimeMillis()) {
plusScore = false; //Unsure if working as relying on above
}
}
这(下)在这里,我呼吁布尔,我包括方法的第一部分,我不知道是否有可能是可能发生的冲突。
public void draw(Canvas canvas) {
for(Obstacle ob : obstacles)
ob.draw(canvas);
Paint paint = new Paint();
paint.setTextSize(100);
paint.setColor(Color.BLACK);
canvas.drawText(" " + score, 50, 50 + paint.descent() - paint.ascent(), paint);
if(plusScore) { //This is what the Boolean should effect
Paint paint2 = new Paint();
paint2.setTextSize(100);
paint2.setColor(Color.GREEN);
drawPlusScore(canvas, paint2, "+10!");
}
}
[我想弄清楚的时候没有平局方法工作正常,如果声明] 如果问题很明显我很抱歉,我在下面的第一次的教程,并决定尝试一些我自己。
满足以下条件:obstacle.get(barriers.size() - 1).getRectangle()。top> = Constants.SCREEN_HEIGHT –
是的,它每次离开屏幕时都会将分数提高10已经在模拟器中检查过) – George
我怀疑赛车状况。试着重置'draw'中的布尔值而不是'update' - > put'plusScore = false;'作为'if(plusScore)'中的第一个语句。在不同的线程上调用'update'和'draw'?如果是这样,尽量让它变得不稳定。 – Fildor