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

fix: change clickSound and hoverSound in FlxSlider into a FlxSounds #453

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
21 changes: 17 additions & 4 deletions flixel/addons/ui/FlxSlider.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import flixel.group.*;
import flixel.math.FlxMath;
import flixel.math.FlxPoint;
import flixel.math.FlxRect;
import flixel.sound.FlxSound;
import flixel.text.FlxText;
import flixel.util.FlxColor;
import flixel.util.FlxDestroyUtil;
import flixel.util.FlxSpriteUtil;


/**
* A slider GUI element for float and integer manipulation.
* @author Gama11
Expand Down Expand Up @@ -71,13 +73,15 @@ class FlxSlider extends #if (flixel < "5.7.0") FlxSpriteGroup #else FlxSpriteCon

/**
* Sound that's played whenever the slider is clicked.
* No sound is set by default, you must call one of the load methods from `FlxSound` to set it (e.g. `clickSound.loadEmbedded()`).
*/
public var clickSound:String;
public var clickSound:FlxSound;

/**
* Sound that's played whenever the slider is hovered over.
* No sound is set by default, you must call one of the load methods from `FlxSound` to set it (e.g. `clickSound.loadEmbedded()`).
*/
public var hoverSound:String;
public var hoverSound:FlxSound;

/**
* The alpha value the slider uses when it's hovered over. 1 to turn the effect off.
Expand Down Expand Up @@ -213,6 +217,12 @@ class FlxSlider extends #if (flixel < "5.7.0") FlxSpriteGroup #else FlxSpriteCon
_color = Color;
_handleColor = HandleColor;

clickSound = new FlxSound();
hoverSound = new FlxSound();

FlxG.sound.defaultSoundGroup.add(clickSound);
FlxG.sound.defaultSoundGroup.add(hoverSound);

// Create the slider
createSlider();
}
Expand Down Expand Up @@ -291,7 +301,7 @@ class FlxSlider extends #if (flixel < "5.7.0") FlxSpriteGroup #else FlxSpriteCon
#if FLX_SOUND_SYSTEM
if (hoverSound != null && !_justHovered)
{
FlxG.sound.play(hoverSound);
hoverSound.play();
}
#end

Expand All @@ -305,7 +315,7 @@ class FlxSlider extends #if (flixel < "5.7.0") FlxSpriteGroup #else FlxSpriteCon
#if FLX_SOUND_SYSTEM
if (clickSound != null && !_justClicked)
{
FlxG.sound.play(clickSound);
clickSound.play();
_justClicked = true;
}
#end
Expand Down Expand Up @@ -438,6 +448,9 @@ class FlxSlider extends #if (flixel < "5.7.0") FlxSpriteGroup #else FlxSpriteCon

_bounds = FlxDestroyUtil.put(_bounds);

clickSound = FlxDestroyUtil.destroy(clickSound);
hoverSound = FlxDestroyUtil.destroy(hoverSound);

super.destroy();
}

Expand Down
Loading