@@ -141,6 +141,28 @@ typedef PlayStateParams =
141141 * Used to persist the position of the `cameraFollowPosition` between levels.
142142 */
143143 ? cameraFollowPoint : FlxPoint ,
144+ /**
145+ * The volume parameters for music tracks.
146+ */
147+ ? volume : PlayStateVolumeParams
148+ }
149+
150+ typedef PlayStateVolumeParams =
151+ {
152+ /**
153+ * The volume of the instrumental.
154+ */
155+ var ? inst : Float ;
156+
157+ /**
158+ * The volume of the player vocals.
159+ */
160+ var ? player : Float ;
161+
162+ /**
163+ * The volume of the opponent vocals.
164+ */
165+ var ? opponent : Float ;
144166}
145167
146168/**
@@ -239,6 +261,24 @@ class PlayState extends MusicBeatSubState
239261 */
240262 public var playbackRate : Float = 1.0 ;
241263
264+ /**
265+ * The volume of the instrumental track.
266+ * @default `1.0` for 100%.
267+ */
268+ public var instrumentalVolume : Float = 1.0 ;
269+
270+ /**
271+ * The volume of the player vocals track.
272+ * @default `1.0` for 100%.
273+ */
274+ public var playerVocalsVolume : Float = 1.0 ;
275+
276+ /**
277+ * The volume of the opponent vocals track.
278+ * @default `1.0` for 100%.
279+ */
280+ public var opponentVocalsVolume : Float = 1.0 ;
281+
242282 /**
243283 * An empty FlxObject contained in the scene.
244284 * The current gameplay camera will always follow this object. Tween its position to move the camera smoothly.
@@ -712,6 +752,10 @@ class PlayState extends MusicBeatSubState
712752 overrideMusic = params .overrideMusic ?? false ;
713753 previousCameraFollowPoint = params .cameraFollowPoint ;
714754
755+ instrumentalVolume = params .volume ?. inst ?? 1.0 ;
756+ playerVocalsVolume = params .volume ?. player ?? 1.0 ;
757+ opponentVocalsVolume = params .volume ?. opponent ?? 1.0 ;
758+
715759 // Basic object initialization
716760
717761 // TODO: Add something to toggle this on!
@@ -1028,16 +1072,15 @@ class PlayState extends MusicBeatSubState
10281072 }
10291073 }
10301074
1031- if (FlxG .sound .music != null ) FlxG .sound .music .volume = 1 ;
1075+ if (FlxG .sound .music != null ) FlxG .sound .music .volume = instrumentalVolume ;
10321076
10331077 if (vocals != null )
10341078 {
10351079 vocals .pause ();
10361080 vocals .time = startTimestamp - Conductor .instance .instrumentalOffset ;
10371081
1038- vocals .volume = 1 ;
1039- vocals .playerVolume = 1 ;
1040- vocals .opponentVolume = 1 ;
1082+ vocals .playerVolume = playerVocalsVolume ;
1083+ vocals .opponentVolume = opponentVocalsVolume ;
10411084 }
10421085
10431086 if (! fromDeathState )
@@ -2512,7 +2555,7 @@ class PlayState extends MusicBeatSubState
25122555 }
25132556
25142557 // Prevent the volume from being wrong.
2515- FlxG .sound .music .volume = 1.0 ;
2558+ FlxG .sound .music .volume = instrumentalVolume ;
25162559 if (FlxG .sound .music .fadeTween != null ) FlxG .sound .music .fadeTween .cancel ();
25172560
25182561 if (vocals != null )
@@ -2522,7 +2565,8 @@ class PlayState extends MusicBeatSubState
25222565
25232566 vocals .time = startTimestamp - Conductor .instance .instrumentalOffset ;
25242567 vocals .pitch = playbackRate ;
2525- vocals .volume = 1.0 ;
2568+ vocals .playerVolume = playerVocalsVolume ;
2569+ vocals .opponentVolume = opponentVocalsVolume ;
25262570
25272571 // trace('STARTING SONG AT:');
25282572 // trace('${FlxG.sound.music.time}');
@@ -2986,7 +3030,7 @@ class PlayState extends MusicBeatSubState
29863030 playerStrumline .hitNote (note , ! event .isComboBreak );
29873031 if (event .doesNotesplash ) playerStrumline .playNoteSplash (note .noteData .getDirection ());
29883032 if (note .isHoldNote && note .holdNoteSprite != null ) playerStrumline .playNoteHoldCover (note .holdNoteSprite );
2989- if (vocals != null ) vocals .playerVolume = 1 ;
3033+ if (vocals != null ) vocals .playerVolume = playerVocalsVolume ;
29903034
29913035 // Display the combo meter and add the calculation to the score.
29923036 if (note .scoreable )
@@ -3225,7 +3269,7 @@ class PlayState extends MusicBeatSubState
32253269 comboPopUps .displayRating (daRating );
32263270 if (combo >= 10 ) comboPopUps .displayCombo (combo );
32273271
3228- if (vocals != null ) vocals .playerVolume = 1 ;
3272+ if (vocals != null ) vocals .playerVolume = playerVocalsVolume ;
32293273 }
32303274
32313275 /**
0 commit comments