Skip to content

Commit

Permalink
Add pitch to FlxSound demo (#358)
Browse files Browse the repository at this point in the history
* add pitch to flxsound demo

one more conditional...

another one whoops

Add pitch to FlxSound demo

* defines

* include mp3 only on flash
  • Loading branch information
ACrazyTown authored Oct 8, 2024
1 parent b1e2d5e commit 16de61c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Features/FlxSound/Project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<set name="BUILD_DIR" value="export" />
<source path="source" />
<assets path="assets/xml" />
<assets path="assets/sounds" include="*.mp3" />
<assets path="assets/sounds" include="*.mp3" if="flash" />
<assets path="assets/sounds" include="*.ogg" unless="flash" />

<!-- _______________________________ Libraries ______________________________ -->
Expand Down
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 FLX_PITCH
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 FLX_NO_PITCH
_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 FLX_PITCH
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 FLX_PITCH
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 FLX_PITCH
FlxG.sound.music.pitch = music_pitch;
#end
FlxG.sound.music.onComplete = musicComplete;
enablePause(true);
}
Expand Down

0 comments on commit 16de61c

Please sign in to comment.