onPush method

  1. @mustCallSuper
void onPush({
  1. double? fadeLength,
})

What should happen when this level is pushed into a level stack.

If fadeLength is not null, then music and all ambiances will be faded in.

Implementation

@mustCallSuper
void onPush({final double? fadeLength}) {
  final sound = music;
  if (sound != null) {
    musicSound = game.musicSounds.playSound(
      assetReference: fadeLength == null ? sound : sound.silent(),
      keepAlive: true,
      looping: true,
    );
    if (fadeLength != null) {
      musicSound!.fade(
        length: fadeLength,
        endGain: sound.gain,
        startGain: 0.0,
      );
    }
  }
  for (final ambiance in ambiances) {
    final SoundChannel channel;
    final position = ambiance.position;
    if (position == null) {
      channel = game.ambianceSounds;
    } else {
      channel = game.createSoundChannel(
        position: SoundPosition3d(x: position.x, y: position.y),
      );
    }
    final assetReference = ambiance.sound;
    final sound = channel.playSound(
      assetReference:
          fadeLength == null ? assetReference : assetReference.silent(),
      keepAlive: true,
      looping: true,
    );
    if (fadeLength != null) {
      sound.fade(
        length: fadeLength,
        startGain: 0.0,
        endGain: assetReference.gain,
      );
    }
    ambiancePlaybacks[ambiance] = SoundPlayback(channel, sound);
  }
  randomSounds.forEach(scheduleRandomSound);
}