kokoichi206 / rhythm_game

Android rhythm game
0 stars 0 forks source link

It suddenly starts descending many notes #47

Closed kokoichi206 closed 3 years ago

kokoichi206 commented 3 years ago

Describe the bug Start descending many notes suddenly

To Reproduce Steps to reproduce the behavior:

  1. Tap the pause button.
  2. Tap space other than dialog area.
  3. Tap the pause button again.
  4. Tap the "continue" button to restart the game.

probability of occurrence 5/5

Expected behavior We can tap only the dialog space.

Screenshots

Screenshot_20210827-011939

Environments:

(This bug also occurs in Nexus5 (Android 6))

Additional context The music player does not show the expected behavior either. After the step4 of the "to produce", the music starts playing from the beginning.

kokoichi206 commented 3 years ago

About the Problem

Now, when the pause button is clicked, the following procedure will happen (in returnHomeCheck())

MediaPlayer

  1. Pause the MediaPlayer
  2. Save the time music have been played as a temporary variable.
  3. Only after the positive button is tapped 3.1. Start the music from the beginning 3.2. Seek to the position saved at step2

If the positive button is not tapped, the saved position of music will disappear.

That's why the music starts playing from the beginning in the bug.

Corresponding Codes
```java public void returnHomeCheck() { ... // step 1 MyMediaPlayer.player.pause(); // step 2 musicLength = MyMediaPlayer.player.getCurrentPosition(); ... final int finalMusicLength = musicLength; builder.setPositiveButton(R.string.pause_dialog_continue, new DialogInterface.OnClickListener() { // step 3 public void onClick(DialogInterface dialog, int id) { // step 3.1 MyMediaPlayer.player.start(); // step 3.2 MyMediaPlayer.player.seekTo(finalMusicLength); // restart the game loop resume(); } }); } ```

Notes ( = The green circles we tap with music)

  1. Now, we manage the timing of Notes by system date.
  2. Record the current datetime (as the time the dialog shows up)
  3. Stop the game loop (stop descending notes)
  4. Only after the positive button is tapped 3.1. Record the current datetime (as the time the dialog closes) 3.2. Shift the "Game loop start time" 3.3. Restart the game loop (start descending notes according to a new "Game loop start time")
Corresponding Codes
```java public void returnHomeCheck() { // step 1 long dialogStartedAt = System.currentTimeMillis(); pause(); ... builder.setPositiveButton(R.string.pause_dialog_continue, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // step 2.1 long dialogEndedAt = System.currentTimeMillis(); // step 2.2 // Shift the started time to adjust the descending start timing. loopStartedAt += dialogEndedAt - dialogStartedAt; // restart the game loop resume(); } }); } ```

What is the problem?

Timing management system are ONLY called in a positive button listener function

The solution

kokoichi206 commented 3 years ago

Change finish() position

See 1bd5f84488d527960850fa51a63dabfa48054b75