我在做一個小遊戲在Processing這是類似於吉他英雄風格的遊戲,我試圖做兩件事情:處理P5 - 計時器問題與米利斯()
- 當遊戲加載,停止移動
- 在遊戲過程中的時間,允許暫停功能
現在,我知道我不能停止,因爲米利斯(時間)返回毫秒,因爲應用程序啓動,所以我的計時器將需要millis() - millis()
在開始時相等零,所以當用戶按下START時,他們顯然可以在開始時啓動。遊戲在開始時讀取文件,類似於字幕文件,其中包含要播放的音符以及它應該出現在屏幕上的時間(以毫秒爲單位)。
我的問題是,當我暫停遊戲時,計時器繼續運行,當我取消暫停遊戲時,由於我的邏輯,所有筆記都會「聚攏」,正如您從我的代碼中看到的那樣。
有人可以建議比我使用的算法更好的算法嗎?它的晚了,我一直在這一整天都在努力。我認爲問題是與for()
下面:
public void draw()
{
if (gameInProgress)
{
currentTimerValue = millis(); // Update the timer with the current milliseconds
// Check to see if the note times falls between the current time, or since the last loop (difficult to match exact millisecond)
for(int i=0 ; i<songNotes.length ; i++)
{
if(songNotes[i].getStartTime() > previousTimerValue && songNotes[i].getStartTime() <=currentTimerValue)
notes.add(songNotes[i]);
}
noStroke();
textFont(f,18);
drawButtons(); //Draws coloured buttons relating to Button presses on the controller
drawHighScoreBox(); // Draws high score box up top right
drawLines(); // Draws the strings
moveNotes(); // Moves the notes across from right to left
//Now set the cutoff for oldest note to display
previousTimerValue=currentTimerValue; //Used everytime on the following loop
}
else
{
drawMenu(); // Draw the Main/Pause menu
}
}
注:布爾gameInProgress
如下設置時,用戶按下暫停按鈕,例如「P」,並songNotes
是Note
類型的對象的數組,我寫自己。它有2個成員變量,noteToBePlayed
和timeToBePlayed
。方法getStartTime()
返回timeToBePlayed
,這是一個毫秒值。
任何幫助表示讚賞。 謝謝
哇,我知道這很簡單!我想我需要一個額外的數字值來跟蹤偏移量,但不能把我的頭圍繞它。謝謝。 – eoinzy