FlxSound
Port of org.flixel.FlxSound.
Extends FlxBasic and drives playback through a FlxSoundHandle obtained from the active FlxAudioBackend. All authoritative state (volume, fade, proximity, loop, alive/exists) lives on this object; the handle is a platform-specific playback delegate.
export declare class FlxSound extends FlxBasicProperties
| Property | Modifiers | Type | Description |
|---|---|---|---|
amplitude | - | number | Smoothed peak amplitude 0–1 (combined). |
amplitudeLeft | - | number | Smoothed peak amplitude for the left channel (same as amplitude in stereo panner). |
amplitudeRight | - | number | Smoothed peak amplitude for the right channel (same as amplitude in stereo panner). |
artist | - | string | Metadata artist string (informational only). |
autoDestroy | - | boolean | If true, destroy() is called automatically when playback finishes. |
effectiveVolume | readonly | number | Effective gain after global, group, instance, and proximity attenuation. |
group | - | FlxSoundGroup | null | Hierarchical volume/mute bus used by this sound. |
name | - | string | Sound name for identification and debugging. |
survive | - | boolean | If true, this sound survives state switches. |
volume | - | number | Per-instance volume (0–1). |
x | - | number | World x position for proximity audio. |
y | - | number | World y position for proximity audio. |
Methods
attachTo()
attachTo(source: FlxObject, options: FlxSoundAttachmentOptions): FlxSoundFollow a world object and spatialize it relative to a listener. Camera visibility may pause or stop playback automatically.
Parameters:
| Parameter | Type | Description |
|---|---|---|
source | FlxObject | - |
options | FlxSoundAttachmentOptions | - |
Returns: FlxSound
destroy()
destroy(): voidRelease the backend handle and clean up.
Returns: void
detach()
detach(): FlxSoundStop following the attached object and restore ordinary playback.
Returns: FlxSound
fadeIn()
fadeIn(duration: number): voidFade the volume in from 0 over duration seconds.
Parameters:
| Parameter | Type | Description |
|---|---|---|
duration | number | - |
Returns: void
fadeOut()
fadeOut(duration: number, callback?: (() => void) | null): voidFade the volume out over duration seconds.
Parameters:
| Parameter | Type | Description |
|---|---|---|
duration | number | Fade time in seconds. |
callback | (() => void) | null | Called when the fade completes. |
Returns: void
getActualVolume()
getActualVolume(): numberEffective volume accounting for global volume and mute.
Returns: number
kill()
kill(): voidKill the sound: stop playback and mark dead/nonexistent.
Returns: void
loadEmbedded()
loadEmbedded(source: unknown, loop?: boolean, autoDestroy?: boolean): FlxSoundLoad an embedded sound asset.
Parameters:
| Parameter | Type | Description |
|---|---|---|
source | unknown | An AudioBuffer, URL string, or asset alias. |
loop | boolean | Whether the sound should loop. |
autoDestroy | boolean | Whether to auto-destroy when done. |
Returns: FlxSound
loadStream()
loadStream(url: string, loop?: boolean, autoDestroy?: boolean): FlxSoundLoad a streaming sound from a URL.
Parameters:
| Parameter | Type | Description |
|---|---|---|
url | string | The streaming URL. |
loop | boolean | Whether the sound should loop. |
autoDestroy | boolean | Whether to auto-destroy when done. |
Returns: FlxSound
pause()
pause(): voidPause playback.
Returns: void
play()
play(forceRestart?: boolean): voidStart or restart playback.
Parameters:
| Parameter | Type | Description |
|---|---|---|
forceRestart | boolean | - |
Returns: void
proximity()
proximity(x: number, y: number, target: FlxObject, radius: number, pan?: boolean): FlxSoundConfigure proximity-based volume and panning.
Parameters:
| Parameter | Type | Description |
|---|---|---|
x | number | Source x position. |
y | number | Source y position. |
target | FlxObject | The object to measure distance from (typically the player or camera). |
radius | number | Maximum audible distance. |
pan | boolean | Whether to apply stereo panning based on horizontal offset. |
Returns: FlxSound
resume()
resume(): voidResume from pause.
Returns: void
stop()
stop(): voidStop playback and reset position.
Returns: void
update()
update(): voidPer-frame update: fades, proximity, auto-destroy, amplitude.
Returns: void