Skip to content

Commit

Permalink
add pitch to flxsound demo
Browse files Browse the repository at this point in the history
one more conditional...

another one whoops

Add pitch to FlxSound demo
  • Loading branch information
ACrazyTown committed Oct 7, 2024
1 parent 3e1fca1 commit 66786ff
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Features/FlxSound/assets/xml/menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@
<numeric_stepper id="music_volume" x="5" y="5" step="0.1" value="0.5" min="0.0" max="1.0" decimals="1">
<anchor y="sfx_volume.bottom" y-flush="top"/>
</numeric_stepper>

<numeric_stepper id="music_pitch" x="5" y="5" step="0.1" value="1.0" min="0.0" max="2.0" decimals="1">
<anchor y="music_volume.bottom" y-flush="top"/>
</numeric_stepper>

<text id="sfx_volume_label" x="sfx_volume.right+5" y="sfx_volume.y" text="sfx volume" color="white"/>
<text id="music_volume_label" x="music_volume.right+5" y="music_volume.y" text="music volume" color="white"/>
<text id="music_pitch_label" x="music_pitch.right+5" y="music_pitch.y" text="music pitch" color="white"/>
</data>
20 changes: 20 additions & 0 deletions Features/FlxSound/source/MenuState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class MenuState extends FlxUIState
{
var loop_music:Bool = false;
var music_volume:Float = 0.5;
#if !flash
var music_pitch:Float = 1.0;
#end
var sfx_volume:Float = 0.5;
var loop_count:Int = 0;

Expand All @@ -38,6 +41,11 @@ class MenuState extends FlxUIState

var butt_pause:FlxUIButton = cast _ui.getAsset("butt_pause");
enablePause(false);

#if flash
_ui.removeAsset("music_pitch");
_ui.removeAsset("music_pitch_label");
#end
}

override public function getEvent(name:String, sender:Dynamic, data:Dynamic, ?params:Array<Dynamic>):Void
Expand Down Expand Up @@ -72,9 +80,18 @@ class MenuState extends FlxUIState
{
sfx_volume = nums.value;
}
#if !flash
else if (wname == "music_pitch")
{
music_pitch = nums.value;
}
#end
if (FlxG.sound.music != null && FlxG.sound.music.exists)
{
FlxG.sound.music.volume = music_volume;
#if !flash
FlxG.sound.music.pitch = music_pitch;
#end
}
for (sound in FlxG.sound.list.members)
{
Expand Down Expand Up @@ -124,6 +141,9 @@ class MenuState extends FlxUIState
{
fuib.toggled = true;
FlxG.sound.playMusic(sound_id, music_volume, loop_music);
#if !flash
FlxG.sound.music.pitch = music_pitch;
#end
FlxG.sound.music.onComplete = musicComplete;
enablePause(true);
}
Expand Down

0 comments on commit 66786ff

Please sign in to comment.