Skip to content

Commit

Permalink
fix: change clickSound and hoverSound in FlxSlider into a `FlxS…
Browse files Browse the repository at this point in the history
…ound`s
  • Loading branch information
ninjamuffin99 committed Jan 1, 2025
1 parent 80e115c commit 82ba27f
Showing 1 changed file with 17 additions and 4 deletions.
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

0 comments on commit 82ba27f

Please sign in to comment.