Skip to main content

FlxSound

Kindclass
Packageflixel.sound
Full nameflixel.sound.FlxSound
Sourcesource/source-haxelib-patches/flixel/sound/FlxSound.hx
ExtendsFlxBasic

Public fields​

NameTypeStaticDefaultNotes
contextSoundContextnoSFX#if FLX_SOUND_FILTERS · this uses some code from troll engine for audio effects made by NebulaZorua
filterALFilterno—property (default, set) · #if FLX_SOUND_FILTERS · Filter which gets applied to the sound
effectNull<ALEffect>no—property (default, set) · #if FLX_SOUND_FILTERS · Effect which gets applied to the sound
xFloatno—The x position of this sound in world coordinates. Only really matters if you are doing proximity/panning stuff.
yFloatno—The y position of this sound in world coordinates. Only really matters if you are doing proximity/panning stuff.
persistBoolno—Whether or not this sound should be automatically destroyed when you switch states.
nameStringno—property (default, null) · The ID3 song name. Defaults to null. Currently only works for streamed sounds.
artistStringno—property (default, null) · The ID3 artist name. Defaults to null. Currently only works for streamed sounds.
amplitudeFloatno—property (default, null) · Stores the average wave amplitude of both stereo channels
amplitudeLeftFloatno—property (default, null) · Just the amplitude of the left stereo channel
amplitudeRightFloatno—property (default, null) · Just the amplitude of the right stereo channel
autoDestroyBoolno—Whether to call destroy() when the sound has finished playing.
onCompleteVoid->Voidno—Tracker for sound complete callback. If assigned, will be called each time when sound reaches its end.
panFloatno—property (get, set) · Pan amount. -1 = full left, 1 = full right. Proximity based panning overrides this.
playingBoolno—property (get, never) · Whether or not the sound is currently playing.
volumeFloatno—property (get, set) · Set volume to a value between 0 and 1 to change how this sound is.
pitchFloatno—property (get, set) · #if FLX_PITCH · Set pitch, which also alters the playback speed. Default is 1.
timeFloatno—property (get, set) · The position in runtime of the music playback in milliseconds. If set while paused, changes only come into effect after a resume() call.
lengthFloatno—property (get, never) · The length of the sound in milliseconds. @since 4.2.0
groupFlxSoundGroupno—property (default, set) · 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).
loopedBoolno—Whether or not this sound should loop.
loopTimeFloatno0In case of looping, the point (in milliseconds) from where to restart the sound when it loops back @since 4.1.0
endTimeNull<Float>no—At which point to stop playing the sound, in milliseconds. If not set / null, the sound completes normally. @since 4.2.0
fadeTweenFlxTweenno—The tween used to fade this sound's volume in and out (set via fadeIn() and fadeOut()) @since 4.1.0
pitchFloatno—property (get, set) · `#if flash \

Public methods​

new (constructor)​

function new()

The FlxSound constructor gets all the variables initialized, but NOT ready to play a sound yet.

View source

destroy​

override function destroy():Void

View source

update​

override function update(elapsed:Float):Void

Handles fade out, fade in, panning, proximity, and amplitude operations each frame.

ParameterTypeDefault
elapsedFloat—

View source

kill​

override function kill():Void

View source

loadEmbedded​

function loadEmbedded(EmbeddedSound:FlxSoundAsset, Looped:Bool = false, AutoDestroy:Bool = false, ?OnComplete:Void->Void):FlxSound

One of the main setup functions for sounds, this function loads a sound from an embedded MP3.

@param EmbeddedSound An embedded Class object representing an MP3 file. @param Looped Whether or not this sound should loop endlessly. @param 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. @param OnComplete Called when the sound finished playing @return This FlxSound instance (nice for chaining stuff together, if you're into that).

ParameterTypeDefault
EmbeddedSoundFlxSoundAsset—
Looped (optional)Boolfalse
AutoDestroy (optional)Boolfalse
OnComplete (optional)Void->Void—

View source

loadStream​

function loadStream(SoundURL:String, Looped:Bool = false, AutoDestroy:Bool = false, ?OnComplete:Void->Void, ?OnLoad:Void->Void):FlxSound

One of the main setup functions for sounds, this function loads a sound from a URL.

@param SoundURL A string representing the URL of the MP3 file you want to play. @param Looped Whether or not this sound should loop endlessly. @param 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. @param OnComplete Called when the sound finished playing @param OnLoad Called when the sound finished loading. @return This FlxSound instance (nice for chaining stuff together, if you're into that).

ParameterTypeDefault
SoundURLString—
Looped (optional)Boolfalse
AutoDestroy (optional)Boolfalse
OnComplete (optional)Void->Void, ?OnLoad:Void->Void—

View source

proximity​

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

@param X The X position of the sound. @param Y The Y position of the sound. @param TargetObject The object you want to track. @param Radius The maximum distance this sound can travel. @param Pan Whether panning should be used in addition to the volume changes. @return This FlxSound instance (nice for chaining stuff together, if you're into that).

ParameterTypeDefault
XFloat—
YFloat—
TargetObjectFlxObject—
RadiusFloat—
Pan (optional)Booltrue

View source

play​

function play(ForceRestart:Bool = false, StartTime:Float = 0.0, ?EndTime:Float):FlxSound

Call this function to play the sound - also works on paused sounds.

@param 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. @param StartTime At which point to start playing the sound, in milliseconds. @param EndTime At which point to stop playing the sound, in milliseconds. If not set / null, the sound completes normally.

ParameterTypeDefault
ForceRestart (optional)Boolfalse
StartTime (optional)Float0.0
EndTime (optional)Float—

View source

resume​

function resume():FlxSound

Unpause a sound. Only works on sounds that have been paused.

View source

pause​

function pause():FlxSound

Call this function to pause this sound.

View source

stop​

inline function stop():FlxSound

Call this function to stop this sound.

View source

fadeOut​

inline function fadeOut(Duration:Float = 1, To:Float = 0, ?onComplete:FlxTween->Void):FlxSound

Helper function that tweens this sound's volume.

@param Duration The amount of time the fade-out operation should take. @param To The volume to tween to, 0 by default.

ParameterTypeDefault
Duration (optional)Float1
To (optional)Float0
onComplete (optional)FlxTween->Void—

View source

fadeIn​

inline function fadeIn(Duration:Float = 1, From:Float = 0, To:Float = 1, ?onComplete:FlxTween->Void):FlxSound

Helper function that tweens this sound's volume.

@param Duration The amount of time the fade-in operation should take. @param From The volume to tween from, 0 by default. @param To The volume to tween to, 1 by default.

ParameterTypeDefault
Duration (optional)Float1
From (optional)Float0
To (optional)Float1
onComplete (optional)FlxTween->Void—

View source

getActualVolume​

inline function getActualVolume():Float

Returns the currently selected "real" volume of the sound (takes fades and proximity into account).

@return The adjusted volume of the sound.

View source

setPosition​

inline function setPosition(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.

@param X The new x position @param Y The new y position

ParameterTypeDefault
X (optional)Float0
Y (optional)Float0

View source

toString​

override function toString():String

View source

Internals​

Private / internal members
FieldTypeStatic
effectAuxALAuxiliaryEffectSlotno
_soundSoundno
_channelSoundChannelno
_transformSoundTransformno
_pausedBoolno
_volumeFloatno
_timeFloatno
_lengthFloatno
_pitchFloatno
_volumeAdjustFloatno
_targetFlxObjectno
_radiusFloatno
_proximityPanBoolno
_alreadyPausedBoolno
_pitchFloatno
Method
function set_filter(v:ALFilter)
function set_effect(v:ALEffect)
function reset():Void
function init(Looped:Bool = false, AutoDestroy:Bool = false, ?OnComplete:Void->Void):FlxSound
function volumeTween(f:Float):Void
function updateTransform():Void
function startSound(StartTime:Float):Void
function stopped(?_):Void
function cleanup(destroySound:Bool, resetPosition:Bool = true):Void
function gotID3(_):Void
function onFocus():Void
function onFocusLost():Void
function set_group(value:FlxSoundGroup):FlxSoundGroup
inline function get_playing():Bool
inline function get_volume():Float
function set_volume(Volume:Float):Float
inline function get_pitch():Float
function set_pitch(v:Float):Float
inline function get_pitch():Float
inline function set_pitch(v:Float):Float
inline function get_pan():Float
inline function set_pan(pan:Float):Float
inline function get_time():Float
function set_time(time:Float):Float
inline function get_length():Float