class SoundFrontEnd
package flixel.system.frontEnds
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.
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
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, Looped:Bool = false, ?Group:FlxSoundGroup, AutoDestroy:Bool = false, AutoPlay:Bool = false, ?URL:String, ?OnComplete:() ‑> Void, ?OnLoad:() ‑> Void):FlxSound
Creates a new FlxSound object.
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, 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.
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(Music:FlxSoundAsset, Volume:Float = 1, Looped:Bool = true, ?Group:FlxSoundGroup):Void
Set up and play a looping background soundtrack.
Parameters:
Music | 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. |
stream(URL:String, Volume:Float = 1, 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.