A FlxSound which adds additional functionality: - Delayed playback via negative song position. - Easy functions for immediate playback and recycling.

Static variables

staticread onlyonVolumeChanged:FlxTypedSignal<Float ‑> Void>

An FlxSignal which is dispatched when the volume changes.

Static methods

staticemptyPartialQueue():Void

@:value({ important : false, persist : false, autoPlay : false, autoDestroy : false, looped : false, volume : 1.0 })staticload(embeddedSound:FlxSoundAsset, volume:Float = 1.0, looped:Bool = false, autoDestroy:Bool = false, autoPlay:Bool = false, persist:Bool = false, ?onComplete:() ‑> Void, ?onLoad:() ‑> Void, important:Bool = false):Null<FunkinSound>

Creates a new FunkinSound object synchronously.

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 FunkinSound instance.

autoPlay

Whether to play the sound immediately or wait for a play() call.

persist

Whether to keep this FunkinSound between states, or destroy it.

onComplete

Called when the sound finished playing.

onLoad

Called when the sound finished loading. Called immediately for succesfully loaded embedded sounds.

important

If true, the sound channel will forcefully be added onto the channel array, even if full. Use sparingly!

Returns:

A FunkinSound object, or null if the sound could not be loaded.

@:value({ autoPlay : true, autoDestroy : false, looped : false, volume : 1.0, end : 1, start : 0 })staticloadPartial(path:String, start:Float = 0, end:Float = 1, volume:Float = 1.0, looped:Bool = false, autoDestroy:Bool = false, autoPlay:Bool = true, ?onComplete:() ‑> Void, ?onLoad:() ‑> Void):Promise_Null_funkin_audio_FunkinSound

Will load a section of a sound file, useful for Freeplay where we don't want to load all the bytes of a song

Parameters:

path

The path to the sound file

start

The start time of the sound file

end

The end time of the sound file

volume

Volume to start at

looped

Whether the sound file should loop

autoDestroy

Whether the sound file should be destroyed after it finishes playing

autoPlay

Whether the sound file should play immediately

onComplete

Callback when the sound finishes playing

onLoad

Callback when the sound finishes loading

Returns:

A FunkinSound object

staticplayMusic(key:String, params:FunkinSoundPlayMusicParams):Bool

Creates a new FunkinSound object and loads it as the current music track.

Parameters:

key

The key of the music you want to play. Music should be at music/<key>/<key>.ogg.

params

A set of additional optional parameters. Data should be at music/<key>/<key>-metadata.json.

Returns:

Whether the music was started. false if music was already playing or could not be started

@:value({ important : false, volume : 1.0 })staticplayOnce(key:String, volume:Float = 1.0, ?onComplete:() ‑> Void, ?onLoad:() ‑> Void, important:Bool = false):Null<FunkinSound>

Play a sound effect once, then destroy it.

Parameters:

key
volume

Returns:

A FunkinSound object, or null if the sound could not be loaded.

staticsetMusic(newMusic:FunkinSound):Void

Replaces the Flixel current music object with the given FunkinSound object.

Parameters:

newMusic

The new music to be set as the current music.

@:value({ persistToo : false, musicToo : false })staticstopAllAudio(musicToo:Bool = false, persistToo:Bool = false):Void

Stop all sounds in the pool and allow them to be recycled.

Constructor

new()

Variables

@:value(false)important:Bool = false

If true, the game will forcefully add this sound's channel to the list of playing sounds.

read onlyisPlaying:Bool

@:value(false)muted:Bool = false

Calculate the current time of the sound. NOTE: You need to add() the sound to the scene for update() to increment the time.

read onlypaused:Bool

read onlywaveformData:WaveformData

Waveform data for this sound. This is lazily loaded, so it will be built the first time it is accessed.

Methods

toString():String

Produces a string representation suitable for debugging.

Inherited Variables

Defined by FlxSound

read onlyamplitude:Float

Stores the average wave amplitude of both stereo channels

read onlyamplitudeLeft:Float

Just the amplitude of the left stereo channel

read onlyamplitudeRight:Float

Just the amplitude of the right stereo channel

read onlyartist:String

The ID3 artist name. Defaults to null. Currently only works for streamed sounds.

autoDestroy:Bool

Whether to call destroy() when the sound has finished playing.

endTime:Null<Float>

At which point to stop playing the sound, in milliseconds. If not set / null, the sound completes normally.

Available since

4.2.0

.

fadeTween:FlxTween

The tween used to fade this sound's volume in and out (set via fadeIn() and fadeOut())

Available since

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).

read onlylength:Float

The length of the sound in milliseconds.

Available since

4.2.0

.

@:value(0)loopTime:Float = 0

In case of looping, the point (in milliseconds) from where to restart the sound when it loops back

Available since

4.1.0

.

looped:Bool

Whether or not this sound should loop.

read onlyname:String

The ID3 song name. Defaults to null. Currently only works for streamed sounds.

onComplete:() ‑> Void

Tracker for sound complete callback. If assigned, will be called each time when sound reaches its end.

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

persist:Bool

Whether or not this sound should be automatically destroyed when you switch states.

pitch:Float

Set pitch, which also alters the playback speed. Default is 1.

read onlyplaying:Bool

Whether or not the sound is currently playing.

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.

volume:Float

Set volume to a value between 0 and 1 to change how this sound is.

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.

Defined by FlxBasic

@:value(idEnumerator++)ID:Int = idEnumerator++

A unique ID starting from 0 and increasing by 1 for each subsequent FlxBasic that is created.

@:value(true)active:Bool = true

Controls whether update() is automatically called by FlxState/FlxGroup.

@:value(true)alive:Bool = true

Useful state for many game objects - "dead" (!alive) vs alive. kill() and revive() both flip this switch (along with exists, but you can override that).

camera:FlxCamera

Gets or sets the first camera of this object.

cameras:Array<FlxCamera>

This determines on which FlxCameras this object will be drawn. If it is null / has not been set, it uses the list of default draw targets, which is controlled via FlxG.camera.setDefaultDrawTarget as well as the DefaultDrawTarget argument of FlxG.camera.add.

read onlycontainer:Null<FlxContainer>

The parent containing this basic, typically if you check this recursively you should reach the state

Available since

5.7.0

.

@:value(true)exists:Bool = true

Controls whether update() and draw() are automatically called by FlxState/FlxGroup.

@:value(true)visible:Bool = true

Controls whether draw() is automatically called by FlxState/FlxGroup.

@:value(0)zIndex:Int = 0

Inherited Methods

Defined by FlxSound

@:value({ To : 1, From : 0, Duration : 1 })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.

@:value({ To : 0, Duration : 1 })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.

@:value({ AutoDestroy : false, Looped : false })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 FlxG.sound.play() and FlxG.sound.stream() will set it to true by default.

Returns:

This FlxSound instance (nice for chaining stuff together, if you're into that).

@:value({ AutoDestroy : false, Looped : false })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.

Note: If the FLX_DEFAULT_SOUND_EXT flag is enabled, you may omit the file extension

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 FlxG.sound.play() and FlxG.sound.stream() will set it to true by default.

OnComplete

Called when the sound finished playing

Returns:

This FlxSound instance (nice for chaining stuff together, if you're into that).

@:value({ AutoDestroy : false, Looped : false })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 FlxG.sound.play() and FlxG.sound.stream() will set it to true by default.

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).

@:value({ Pan : true })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).

@:value({ Y : 0, X : 0 })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

inlinestop():FlxSound

Call this function to stop this sound.

Defined by FlxBasic

draw():Void

Override this function to control how the object is drawn. Doing so is rarely necessary, but can be very useful.

getCameras():Array<FlxCamera>

The cameras that will draw this. Use this.cameras to set specific cameras for this object, otherwise the container's cameras are used, or the container's container and so on. If there is no container, say, if this is inside FlxGroups rather than a FlxContainer then the default draw cameras are returned.

Available since

5.7.0

.

getDefaultCamera():FlxCamera

The main camera that will draw this. Use this.cameras to set specific cameras for this object, otherwise the container's camera is used, or the container's container and so on. If there is no container, say, if this is inside FlxGroups rather than a FlxContainer then FlxG.camera is returned.

Available since

5.7.0

.

revive():Void

Handy function for bringing game objects "back to life". Just sets alive and exists back to true. In practice, this function is most often called by FlxObject#reset().