Skip to content

Commit 16de61c

Browse files
authored
Add pitch to FlxSound demo (#358)
* add pitch to flxsound demo one more conditional... another one whoops Add pitch to FlxSound demo * defines * include mp3 only on flash
1 parent b1e2d5e commit 16de61c

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

Features/FlxSound/Project.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<set name="BUILD_DIR" value="export" />
3333
<source path="source" />
3434
<assets path="assets/xml" />
35-
<assets path="assets/sounds" include="*.mp3" />
35+
<assets path="assets/sounds" include="*.mp3" if="flash" />
3636
<assets path="assets/sounds" include="*.ogg" unless="flash" />
3737

3838
<!-- _______________________________ Libraries ______________________________ -->

Features/FlxSound/assets/xml/menu.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@
4141
<numeric_stepper id="music_volume" x="5" y="5" step="0.1" value="0.5" min="0.0" max="1.0" decimals="1">
4242
<anchor y="sfx_volume.bottom" y-flush="top"/>
4343
</numeric_stepper>
44+
45+
<numeric_stepper id="music_pitch" x="5" y="5" step="0.1" value="1.0" min="0.0" max="2.0" decimals="1">
46+
<anchor y="music_volume.bottom" y-flush="top"/>
47+
</numeric_stepper>
4448

4549
<text id="sfx_volume_label" x="sfx_volume.right+5" y="sfx_volume.y" text="sfx volume" color="white"/>
4650
<text id="music_volume_label" x="music_volume.right+5" y="music_volume.y" text="music volume" color="white"/>
51+
<text id="music_pitch_label" x="music_pitch.right+5" y="music_pitch.y" text="music pitch" color="white"/>
4752
</data>

Features/FlxSound/source/MenuState.hx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class MenuState extends FlxUIState
2222
{
2323
var loop_music:Bool = false;
2424
var music_volume:Float = 0.5;
25+
#if FLX_PITCH
26+
var music_pitch:Float = 1.0;
27+
#end
2528
var sfx_volume:Float = 0.5;
2629
var loop_count:Int = 0;
2730

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

3942
var butt_pause:FlxUIButton = cast _ui.getAsset("butt_pause");
4043
enablePause(false);
44+
45+
#if FLX_NO_PITCH
46+
_ui.removeAsset("music_pitch");
47+
_ui.removeAsset("music_pitch_label");
48+
#end
4149
}
4250

4351
override public function getEvent(name:String, sender:Dynamic, data:Dynamic, ?params:Array<Dynamic>):Void
@@ -72,9 +80,18 @@ class MenuState extends FlxUIState
7280
{
7381
sfx_volume = nums.value;
7482
}
83+
#if FLX_PITCH
84+
else if (wname == "music_pitch")
85+
{
86+
music_pitch = nums.value;
87+
}
88+
#end
7589
if (FlxG.sound.music != null && FlxG.sound.music.exists)
7690
{
7791
FlxG.sound.music.volume = music_volume;
92+
#if FLX_PITCH
93+
FlxG.sound.music.pitch = music_pitch;
94+
#end
7895
}
7996
for (sound in FlxG.sound.list.members)
8097
{
@@ -124,6 +141,9 @@ class MenuState extends FlxUIState
124141
{
125142
fuib.toggled = true;
126143
FlxG.sound.playMusic(sound_id, music_volume, loop_music);
144+
#if FLX_PITCH
145+
FlxG.sound.music.pitch = music_pitch;
146+
#end
127147
FlxG.sound.music.onComplete = musicComplete;
128148
enablePause(true);
129149
}

0 commit comments

Comments
 (0)