Accessed via FlxG.sound.
Variables
defaultMusicGroup:FlxSoundGroup = new FlxSoundGroup()
The group sounds played via playMusic() are added to unless specified otherwise.
defaultSoundGroup:FlxSoundGroup = new FlxSoundGroup()
The group sounds in load() / play() / stream() are added to unless specified otherwise.
read onlylist:FlxTypedGroup<FlxSound> = new FlxTypedGroup<FlxSound>()
A list of all the sounds being played in the game.
muteKeys:Array<FlxKey> = [ZERO, NUMPADZERO]
The keys used to mute / unmute the game (see FlxG.keys for the keys available). Default keys: 0 (and numpad 0). Set to null to deactivate.
read onlyonVolumeChange:FlxTypedSignal<Float ‑> Void> = new FlxTypedSignal<Float>()
A signal that gets dispatched whenever the volume changes.
soundTrayEnabled:Bool = true
Whether or not the soundTray should be shown when any of the volumeUp-, volumeDown- or muteKeys is pressed.
volumeDownKeys:Array<FlxKey> = [MINUS, NUMPADMINUS]
The keys to decrease volume (see FlxG.keys for the keys available). Default keys: - (and numpad -). Set to null to deactivate.
volumeUpKeys:Array<FlxKey> = [PLUS, NUMPADPLUS]
The key codes used to increase volume (see FlxG.keys for the keys available). Default keys: + (and numpad +). Set to null to deactivate.
volumeHandler:Float ‑> Void
Set this hook to get a callback whenever the volume changes. Function should take the form myVolumeHandler(volume:Float).
Methods
dynamicapplySoundCurve(volume:Float):Float
Takes the volume scale used by Flixel fields and gives the final transformed volume that is
actually used to play the sound. To reverse this operation, use reverseSoundCurve. This
field is dynamic and can be overwritten.
inlinecache(embeddedSound:String):Sound
Method for sound caching (especially useful on mobile targets). The game may freeze for some time the first time you try to play a sound if you don't use this method.
Parameters:
embeddedSound | Name of sound assets specified in your .xml project file |
|---|
Returns:
Cached Sound object
cacheAll():Void
Calls FlxG.sound.cache() on all sounds that are embedded. WARNING: can lead to high memory usage.
changeVolume(Amount:Float):Void
Changes the volume by a certain amount, also activating the sound tray.
destroy(forceDestroy:Bool = false):Void
Called by FlxGame on state changes to stop and destroy sounds.
Parameters:
forceDestroy | Kill sounds even if persist is true. |
|---|
load(?embeddedSound:Null<FlxSoundAsset>, volume:Float = 1.0, looped:Bool = false, ?group:FlxSoundGroup, autoDestroy:Bool = false, autoPlay:Bool = false, ?url:String, ?onComplete:() ‑> Void, ?onLoad:() ‑> Void):FlxSound
Creates a new FlxSound object.
Note: If the FLX_DEFAULT_SOUND_EXT flag is enabled, you may omit the file extension
Parameters:
embeddedSound | The embedded sound resource you want to play. To stream, use the optional URL parameter instead. |
|---|---|
volume | How loud to play it (0 to 1). |
looped | Whether to loop this sound. |
group | The group to add this sound to. |
autoDestroy | Whether to destroy this sound when it finishes playing. Leave this value set to "false" if you want to re-use this FlxSound instance. |
autoPlay | Whether to play the sound. |
url | Load a sound from an external web resource instead. Only used if EmbeddedSound = null. |
onComplete | Called when the sound finished playing. |
onLoad | Called when the sound finished loading. Called immediately for succesfully loaded embedded sounds. |
Returns:
A FlxSound object.
play(embeddedSound:FlxSoundAsset, volume:Float = 1.0, looped:Bool = false, ?group:FlxSoundGroup, autoDestroy:Bool = true, ?onComplete:() ‑> Void):FlxSound
Plays a sound from an embedded sound. Tries to recycle a cached sound first.
Note: If the FLX_DEFAULT_SOUND_EXT flag is enabled, you may omit the file extension
Parameters:
embeddedSound | The embedded sound resource you want to play. |
|---|---|
volume | How loud to play it (0 to 1). |
looped | Whether to loop this sound. |
group | The group to add this sound to. |
autoDestroy | Whether to destroy this sound when it finishes playing. Leave this value set to "false" if you want to re-use this FlxSound instance. |
onComplete | Called when the sound finished playing |
Returns:
A FlxSound object.
playMusic(embeddedMusic:FlxSoundAsset, volume:Float = 1.0, looped:Bool = true, ?group:FlxSoundGroup):Void
Set up and play a looping background soundtrack.
Note: If the FLX_DEFAULT_SOUND_EXT flag is enabled, you may omit the file extension
Parameters:
embeddedMusic | The sound file you want to loop in the background. |
|---|---|
volume | How loud the sound should be, from 0 to 1. |
looped | Whether to loop this music. |
group | The group to add this sound to. |
dynamicreverseSoundCurve(curvedVolume:Float):Float
Takes a transformed volume and returns the corresponding volume scale used by Flixel fields.
Used to reverse the operation of applySoundCurve. This field is dynamic and can be
set to a custom function.
showSoundTray(up:Bool = false):Void
Shows the sound tray if it is enabled.
Parameters:
up | Whether or not the volume is increasing. |
|---|
stream(url:String, volume:Float = 1.0, looped:Bool = false, ?group:FlxSoundGroup, autoDestroy:Bool = true, ?onComplete:() ‑> Void, ?onLoad:() ‑> Void):FlxSound
Plays a sound from a URL. Tries to recycle a cached sound first. NOTE: Just calls FlxG.sound.load() with AutoPlay == true.
Parameters:
url | Load a sound from an external web resource instead. |
|---|---|
volume | How loud to play it (0 to 1). |
looped | Whether to loop this sound. |
group | The group to add this sound to. |
autoDestroy | Whether to destroy this sound when it finishes playing. Leave this value set to "false" if you want to re-use this FlxSound instance. |
onComplete | Called when the sound finished playing |
onLoad | Called when the sound finished loading. |
Returns:
A FlxSound object.