FlxSound
| Kind | class |
| Package | flixel.sound |
| Full name | flixel.sound.FlxSound |
| Source | source/source-haxelib-patches/flixel/sound/FlxSound.hx |
| Extends | FlxBasic |
Public fields
| Name | Type | Static | Default | Notes |
|---|---|---|---|---|
context | SoundContext | no | SFX | #if FLX_SOUND_FILTERS · this uses some code from troll engine for audio effects made by NebulaZorua |
filter | ALFilter | no | — | property (default, set) · #if FLX_SOUND_FILTERS · Filter which gets applied to the sound |
effect | Null<ALEffect> | no | — | property (default, set) · #if FLX_SOUND_FILTERS · Effect which gets applied to the sound |
x | Float | no | — | The x position of this sound in world coordinates. Only really matters if you are doing proximity/panning stuff. |
y | Float | no | — | The y position of this sound in world coordinates. Only really matters if you are doing proximity/panning stuff. |
persist | Bool | no | — | Whether or not this sound should be automatically destroyed when you switch states. |
name | String | no | — | property (default, null) · The ID3 song name. Defaults to null. Currently only works for streamed sounds. |
artist | String | no | — | property (default, null) · The ID3 artist name. Defaults to null. Currently only works for streamed sounds. |
amplitude | Float | no | — | property (default, null) · Stores the average wave amplitude of both stereo channels |
amplitudeLeft | Float | no | — | property (default, null) · Just the amplitude of the left stereo channel |
amplitudeRight | Float | no | — | property (default, null) · Just the amplitude of the right stereo channel |
autoDestroy | Bool | no | — | Whether to call destroy() when the sound has finished playing. |
onComplete | Void->Void | no | — | Tracker for sound complete callback. If assigned, will be called each time when sound reaches its end. |
pan | Float | no | — | property (get, set) · Pan amount. -1 = full left, 1 = full right. Proximity based panning overrides this. |
playing | Bool | no | — | property (get, never) · Whether or not the sound is currently playing. |
volume | Float | no | — | property (get, set) · Set volume to a value between 0 and 1 to change how this sound is. |
pitch | Float | no | — | property (get, set) · #if FLX_PITCH · Set pitch, which also alters the playback speed. Default is 1. |
time | Float | no | — | 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. |
length | Float | no | — | property (get, never) · The length of the sound in milliseconds. @since 4.2.0 |
group | FlxSoundGroup | no | — | 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). |
looped | Bool | no | — | Whether or not this sound should loop. |
loopTime | Float | no | 0 | In case of looping, the point (in milliseconds) from where to restart the sound when it loops back @since 4.1.0 |
endTime | Null<Float> | no | — | At which point to stop playing the sound, in milliseconds. If not set / null, the sound completes normally. @since 4.2.0 |
fadeTween | FlxTween | no | — | The tween used to fade this sound's volume in and out (set via fadeIn() and fadeOut()) @since 4.1.0 |
pitch | Float | no | — | 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.
destroy
override function destroy():Void
update
override function update(elapsed:Float):Void
Handles fade out, fade in, panning, proximity, and amplitude operations each frame.
| Parameter | Type | Default |
|---|---|---|
elapsed | Float | — |
kill
override function kill():Void
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).
| Parameter | Type | Default |
|---|---|---|
EmbeddedSound | FlxSoundAsset | — |
Looped (optional) | Bool | false |
AutoDestroy (optional) | Bool | false |
OnComplete (optional) | Void->Void | — |
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).
| Parameter | Type | Default |
|---|---|---|
SoundURL | String | — |
Looped (optional) | Bool | false |
AutoDestroy (optional) | Bool | false |
OnComplete (optional) | Void->Void, ?OnLoad:Void->Void | — |
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).
| Parameter | Type | Default |
|---|---|---|
X | Float | — |
Y | Float | — |
TargetObject | FlxObject | — |
Radius | Float | — |
Pan (optional) | Bool | true |
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.
| Parameter | Type | Default |
|---|---|---|
ForceRestart (optional) | Bool | false |
StartTime (optional) | Float | 0.0 |
EndTime (optional) | Float | — |
resume
function resume():FlxSound
Unpause a sound. Only works on sounds that have been paused.
pause
function pause():FlxSound
Call this function to pause this sound.
stop
inline function stop():FlxSound
Call this function to stop this sound.
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.
| Parameter | Type | Default |
|---|---|---|
Duration (optional) | Float | 1 |
To (optional) | Float | 0 |
onComplete (optional) | FlxTween->Void | — |
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.
| Parameter | Type | Default |
|---|---|---|
Duration (optional) | Float | 1 |
From (optional) | Float | 0 |
To (optional) | Float | 1 |
onComplete (optional) | FlxTween->Void | — |
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.
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
| Parameter | Type | Default |
|---|---|---|
X (optional) | Float | 0 |
Y (optional) | Float | 0 |
toString
override function toString():String
Internals
Private / internal members
| Field | Type | Static |
|---|---|---|
effectAux | ALAuxiliaryEffectSlot | no |
_sound | Sound | no |
_channel | SoundChannel | no |
_transform | SoundTransform | no |
_paused | Bool | no |
_volume | Float | no |
_time | Float | no |
_length | Float | no |
_pitch | Float | no |
_volumeAdjust | Float | no |
_target | FlxObject | no |
_radius | Float | no |
_proximityPan | Bool | no |
_alreadyPaused | Bool | no |
_pitch | Float | no |
| 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 |