From e4eb543fa7511180319ccb4b90f9d10a20d1dc67 Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Fri, 15 Mar 2024 21:53:07 -0400 Subject: [PATCH] Fix a bug where title music starts blaringly loud. --- source/funkin/audio/FunkinSound.hx | 17 ++++++++++++----- source/funkin/ui/title/TitleState.hx | 4 ++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/source/funkin/audio/FunkinSound.hx b/source/funkin/audio/FunkinSound.hx index 9efa6ed50..a0bf8c58c 100644 --- a/source/funkin/audio/FunkinSound.hx +++ b/source/funkin/audio/FunkinSound.hx @@ -241,10 +241,16 @@ class FunkinSound extends FlxSound implements ICloneable @:allow(flixel.sound.FlxSoundGroup) override function updateTransform():Void { - _transform.volume = #if FLX_SOUND_SYSTEM ((FlxG.sound.muted || this.muted) ? 0 : 1) * FlxG.sound.volume * #end - (group != null ? group.volume : 1) * _volume * _volumeAdjust; + if (_transform != null) + { + _transform.volume = #if FLX_SOUND_SYSTEM ((FlxG.sound.muted || this.muted) ? 0 : 1) * FlxG.sound.volume * #end + (group != null ? group.volume : 1) * _volume * _volumeAdjust; + } - if (_channel != null) _channel.soundTransform = _transform; + if (_channel != null) + { + _channel.soundTransform = _transform; + } } public function clone():FunkinSound @@ -270,11 +276,12 @@ class FunkinSound extends FlxSound implements ICloneable * Creates a new `FunkinSound` object and loads it as the current music track. * * @param key The key of the music you want to play. Music should be at `music//.ogg`. + * @param startingVolume The volume you want the music to start at. * @param overrideExisting Whether to override music if it is already playing. * @param mapTimeChanges Whether to check for `SongMusicData` to update the Conductor with. * Data should be at `music//-metadata.json`. */ - public static function playMusic(key:String, overrideExisting:Bool = false, mapTimeChanges:Bool = true):Void + public static function playMusic(key:String, startingVolume:Float = 1.0, overrideExisting:Bool = false, mapTimeChanges:Bool = true):Void { if (!overrideExisting && FlxG.sound.music?.playing) return; @@ -292,7 +299,7 @@ class FunkinSound extends FlxSound implements ICloneable } } - FlxG.sound.music = FunkinSound.load(Paths.music('$key/$key')); + FlxG.sound.music = FunkinSound.load(Paths.music('$key/$key'), startingVolume); // Prevent repeat update() and onFocus() calls. FlxG.sound.list.remove(FlxG.sound.music); diff --git a/source/funkin/ui/title/TitleState.hx b/source/funkin/ui/title/TitleState.hx index 1c194d80d..26f6612be 100644 --- a/source/funkin/ui/title/TitleState.hx +++ b/source/funkin/ui/title/TitleState.hx @@ -222,9 +222,9 @@ class TitleState extends MusicBeatState { var shouldFadeIn = (FlxG.sound.music == null); // Load music. Includes logic to handle BPM changes. - FunkinSound.playMusic('freakyMenu', false, true); + FunkinSound.playMusic('freakyMenu', 0.0, false, true); // Fade from 0.0 to 0.7 over 4 seconds - if (shouldFadeIn) FlxG.sound.music.fadeIn(4, 0, 0.7); + if (shouldFadeIn) FlxG.sound.music.fadeIn(4.0, 0.0, 1.0); } function getIntroTextShit():Array>