From 16de61c7e0e174f785f828b9a7500a9c35a9accc Mon Sep 17 00:00:00 2001
From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com>
Date: Tue, 8 Oct 2024 13:16:06 +0200
Subject: [PATCH] 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
---
Features/FlxSound/Project.xml | 2 +-
Features/FlxSound/assets/xml/menu.xml | 5 +++++
Features/FlxSound/source/MenuState.hx | 20 ++++++++++++++++++++
3 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/Features/FlxSound/Project.xml b/Features/FlxSound/Project.xml
index fc9de544c..48afb2611 100644
--- a/Features/FlxSound/Project.xml
+++ b/Features/FlxSound/Project.xml
@@ -32,7 +32,7 @@
-
+
diff --git a/Features/FlxSound/assets/xml/menu.xml b/Features/FlxSound/assets/xml/menu.xml
index d36a881f4..9dd7fa401 100644
--- a/Features/FlxSound/assets/xml/menu.xml
+++ b/Features/FlxSound/assets/xml/menu.xml
@@ -41,7 +41,12 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/Features/FlxSound/source/MenuState.hx b/Features/FlxSound/source/MenuState.hx
index 23cd314f5..b91bdf803 100644
--- a/Features/FlxSound/source/MenuState.hx
+++ b/Features/FlxSound/source/MenuState.hx
@@ -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;
@@ -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):Void
@@ -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)
{
@@ -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);
}