私はProcessingで、GuitarHeroスタイルのゲームに似た小さなゲームを作成しています。2つのことをしようとしています。
- ゲームがロードされたら、時間が移動しないようにします
- ゲーム中に、一時停止機能を許可します
これで、millis()がアプリケーションの起動からミリ秒を返すため、時間を止めることができないことがわかりました。したがって、タイマーは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
どんな助けでも大歓迎です。ありがとう