onPop method

  1. @mustCallSuper
void onPop(
  1. double? fadeLength
)

What should happen when this level is popped from a level stack.

Implementation

@mustCallSuper
void onPop(final double? fadeLength) {
  final sound = musicSound;
  musicSound = null;
  if (sound != null) {
    if (fadeLength == null) {
      sound.destroy();
    } else {
      sound.fade(length: fadeLength);
      game.callAfter(
        func: sound.destroy,
        runAfter: (fadeLength * 1000).floor(),
      );
    }
  }
  for (final ambiance in ambiances) {
    final playback = ambiancePlaybacks.remove(ambiance);
    if (playback == null) {
      continue;
    }
    if (fadeLength != null) {
      playback.sound.fade(length: fadeLength);
      game.callAfter(
        runAfter: (fadeLength * 1000).round(),
        func: () => stopPlayback(playback),
      );
    } else {
      stopPlayback(playback);
    }
  }
  for (final sound in randomSounds) {
    randomSoundNextPlays
        .removeWhere((final element) => element.value == sound);
    final playback = randomSoundPlaybacks.remove(sound);
    if (playback != null) {
      if (fadeLength != null) {
        playback.sound.fade(length: fadeLength);
        game.callAfter(
          runAfter: (fadeLength * 1000).round(),
          func: () => stopPlayback(playback),
        );
      } else {
        stopPlayback(playback);
      }
    }
  }
}