From c4d08463addcf532926308dc319eebb981d530a8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 22 Mar 2021 16:04:51 +0900 Subject: [PATCH] Fix spinners playing looping sound too long in the editor The `OnComplete` event was never being run due to the transform playing out longer than the spinner's lifetime. I've matched the durations, but also moved the `Stop()` call to what I deem a safer place to run it (I did notice that without this it would still potentially never fire). Note that this is more noticeable in the editor because of lifetime extension. In gameplay, the returning of a spinner to the pool will clean things up (but in the editor that can take longer, depending on timeline zoom level). Another thing worth mentioning is that the fade doesn't actually work. This is due to https://github.com/ppy/osu-framework/pull/4212. Closes #12119. --- .../Objects/Drawables/DrawableSpinner.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs index 3d614c2dbd..d92f63eb89 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs @@ -39,6 +39,8 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables private Bindable isSpinning; private bool spinnerFrequencyModulate; + private const double fade_out_duration = 160; + public DrawableSpinner() : this(null) { @@ -136,7 +138,10 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables } else { - spinningSample?.VolumeTo(0, 300).OnComplete(_ => spinningSample.Stop()); + if (spinningSample != null) + spinningSample.Volume.Value = 0; + + spinningSample?.VolumeTo(0, fade_out_duration); } } @@ -173,7 +178,14 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables { base.UpdateHitStateTransforms(state); - this.FadeOut(160).Expire(); + this.FadeOut(fade_out_duration).OnComplete(_ => + { + // looping sample should be stopped here as it is safer than running in the OnComplete + // of the volume transition above. + spinningSample.Stop(); + }); + + Expire(); // skin change does a rewind of transforms, which will stop the spinning sound from playing if it's currently in playback. isSpinning?.TriggerChange();