Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pitch to FlxSound demo #358

Merged
merged 4 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading