-1
我在JavaFX中製作Flappy Bird,並且創建了一種方法來評分。我嘗試過使用時間軸,但如果我經常調用方法,它會變得非常糟糕,如果我使它變慢,則分數會錯誤地增加。我需要一種方法來讓比分法不斷地被調用,而不會讓遊戲變得緩慢和失敗。需要不斷調用方法
下面是得分的方法:
public class Score {
static int score = 0;
static boolean incrementScore = false;
public static int ScoreCount() {
for (int i = 0; i < 100; i++) {
if (FlappyBird.bottomPipes[i].getTranslateX() == Bird.birdView.getTranslateX())
incrementScore = true;
if (incrementScore)
score++;
incrementScore = false;
System.out.println(score);
}
return score;
}
}
如果有人知道一個好辦法做到這一點,請讓我知道。
如果你想運行的程序,它可以下載here
從您發佈的代碼中,我發現您錯過了JavaFX背後的概念。我建議你回到基礎知識,並看看如何完成一個JavaFX應用程序。例如,Score可以保存在一個'IntegerProperty'中,該''IntegerProperty'從UI綁定。 – hotzst
我該怎麼做?我已經看過IngegerProperties,並且我真的不知道這可以怎樣幫助@hotzst – Jackfor