This is the universal flixel sound object, used for streaming, music, and sound effects.
Constructor
new()
The FlxSound constructor gets all the variables initialized, but NOT ready to play a sound yet.
Variables
read onlyartist:String
The ID3 artist name. Defaults to null. Currently only works for streamed sounds.
endTime:Null<Float>
At which point to stop playing the sound, in milliseconds.
If not set / null
, the sound completes normally.
4.2.0
.fadeTween:FlxTween
The tween used to fade this sound's volume in and out (set via fadeIn()
and fadeOut()
)
4.1.0
.group:FlxSoundGroup
The sound group this sound belongs to, can only be in one group.
NOTE: This setter is deprecated, use group.add(sound)
or group.remove(sound)
.
loopTime:Float = 0
In case of looping, the point (in milliseconds) from where to restart the sound when it loops back
4.1.0
.pan:Float
Pan amount. -1 = full left, 1 = full right. Proximity based panning overrides this.
Note: On desktop targets this only works with mono sounds, due to limitations of OpenAL. More info: OpenFL Forums - SoundTransform.pan does not work
time:Float
The position in runtime of the music playback in milliseconds.
If set while paused, changes only come into effect after a resume()
call.
x:Float
The x position of this sound in world coordinates. Only really matters if you are doing proximity/panning stuff.
y:Float
The y position of this sound in world coordinates. Only really matters if you are doing proximity/panning stuff.
onComplete:() ‑> Void
Tracker for sound complete callback. If assigned, will be called each time when sound reaches its end.
Methods
inlinefadeIn(Duration:Float = 1, From:Float = 0, To:Float = 1, ?onComplete:FlxTween ‑> Void):FlxSound
Helper function that tweens this sound's volume.
Parameters:
Duration | The amount of time the fade-in operation should take. |
---|---|
From | The volume to tween from, 0 by default. |
To | The volume to tween to, 1 by default. |
inlinefadeOut(Duration:Float = 1, To:Float = 0, ?onComplete:FlxTween ‑> Void):FlxSound
Helper function that tweens this sound's volume.
Parameters:
Duration | The amount of time the fade-out operation should take. |
---|---|
To | The volume to tween to, 0 by default. |
inlinegetActualVolume():Float
Returns the currently selected "real" volume of the sound (takes fades and proximity into account).
Returns:
The adjusted volume of the sound.
loadByteArray(Bytes:ByteArray, Looped:Bool = false, AutoDestroy:Bool = false, ?OnComplete:() ‑> Void):FlxSound
One of the main setup functions for sounds, this function loads a sound from a ByteArray.
Parameters:
Bytes | A ByteArray object. |
---|---|
Looped | Whether or not this sound should loop endlessly. |
AutoDestroy | Whether or not this FlxSound instance should be destroyed when the sound finishes playing.
Default value is false, but |
Returns:
This FlxSound instance (nice for chaining stuff together, if you're into that).
loadEmbedded(EmbeddedSound:FlxSoundAsset, Looped:Bool = false, AutoDestroy:Bool = false, ?OnComplete:() ‑> Void):FlxSound
One of the main setup functions for sounds, this function loads a sound from an embedded MP3.
Parameters:
EmbeddedSound | An embedded Class object representing an MP3 file. |
---|---|
Looped | Whether or not this sound should loop endlessly. |
AutoDestroy | Whether or not this FlxSound instance should be destroyed when the sound finishes playing.
Default value is false, but |
OnComplete | Called when the sound finished playing |
Returns:
This FlxSound instance (nice for chaining stuff together, if you're into that).
loadStream(SoundURL:String, Looped:Bool = false, AutoDestroy:Bool = false, ?OnComplete:() ‑> Void, ?OnLoad:() ‑> Void):FlxSound
One of the main setup functions for sounds, this function loads a sound from a URL.
Parameters:
SoundURL | A string representing the URL of the MP3 file you want to play. |
---|---|
Looped | Whether or not this sound should loop endlessly. |
AutoDestroy | Whether or not this FlxSound instance should be destroyed when the sound finishes playing.
Default value is false, but |
OnComplete | Called when the sound finished playing |
OnLoad | Called when the sound finished loading. |
Returns:
This FlxSound instance (nice for chaining stuff together, if you're into that).
play(ForceRestart:Bool = false, StartTime:Float = 0.0, ?EndTime:Float):FlxSound
Call this function to play the sound - also works on paused sounds.
Parameters:
ForceRestart | Whether to start the sound over or not. Default value is false, meaning if the sound is already playing or was paused when you call play(), it will continue playing from its current position, NOT start again from the beginning. |
---|---|
StartTime | At which point to start playing the sound, in milliseconds. |
EndTime | At which point to stop playing the sound, in milliseconds.
If not set / |
proximity(X:Float, Y:Float, TargetObject:FlxObject, Radius:Float, Pan:Bool = true):FlxSound
Call this function if you want this sound's volume to change based on distance from a particular FlxObject.
Parameters:
X | The X position of the sound. |
---|---|
Y | The Y position of the sound. |
TargetObject | The object you want to track. |
Radius | The maximum distance this sound can travel. |
Pan | Whether panning should be used in addition to the volume changes. |
Returns:
This FlxSound instance (nice for chaining stuff together, if you're into that).
inlinesetPosition(X:Float = 0, Y:Float = 0):Void
Helper function to set the coordinates of this object. Sound positioning is used in conjunction with proximity/panning.
Parameters:
X | The new x position |
---|---|
Y | The new y position |