Overview
FunkinSound extends FlxSound with additional functionality including delayed playback via negative song position, sound pooling for efficient memory management, and convenient static methods for immediate playback and recycling.
Location: funkin.audio.FunkinSound
Key Features
- Delayed playback support with negative timestamps
- Object pooling for efficient memory reuse
- Waveform data generation and caching
- Music playback with metadata support
- Partial sound loading for optimized memory usage
- Volume change signals
Properties
Bool
Mute this specific sound without affecting volume. When set to
true, the sound is silenced.Bool
Whether the sound is currently paused.
Bool
Returns
true if the sound is playing or scheduled to play (including negative timestamps).WaveformData
Lazily-loaded waveform data for this sound. Generated on first access and cached for subsequent use.
Bool
If
true, forcefully adds this sound’s channel to the playing sounds list even when the channel limit is reached. Use sparingly!Float
The volume level (0.0 to 1.0).
Static Properties
FlxTypedSignal<Float->Void>
A signal dispatched whenever the global volume changes.
FlxTypedGroup<FunkinSound>
Internal pool of FunkinSound instances for efficient recycling.
Methods
play
startTime values for delayed playback.
Bool
default:"false"
If
true, restarts the sound even if already playing.Float
default:"0"
Time in milliseconds to start at. Negative values delay playback.
Float
Time in milliseconds to stop at.
FunkinSound
Returns the sound instance for method chaining.
pause
FunkinSound
Returns the sound instance for method chaining.
resume
FunkinSound
Returns the sound instance for method chaining.
togglePlayback
FunkinSound
Returns the sound instance for method chaining.
clone
FunkinSound
A new FunkinSound instance with cloned data.
Static Methods
load
FlxSoundAsset
required
The sound asset path or embedded sound resource.
Float
default:"1.0"
Initial volume (0.0 to 1.0).
Bool
default:"false"
Whether to loop the sound.
Bool
default:"false"
Whether to destroy the sound when finished. Set to
false to reuse the instance.Bool
default:"false"
Whether to play immediately after loading.
Bool
default:"false"
Whether to keep the sound across state changes.
Void->Void
Callback when the sound finishes playing.
Void->Void
Callback when the sound finishes loading.
Bool
default:"false"
If
true, bypasses channel limits. Use sparingly!Null<FunkinSound>
Returns the loaded sound, or
null if loading failed or channels are exhausted.loadPartial
String
required
The path to the sound file.
Float
default:"0"
Start position as a percentage (0.0 to 1.0).
Float
default:"1"
End position as a percentage (0.0 to 1.0).
Float
default:"1.0"
Initial volume (0.0 to 1.0).
Bool
default:"false"
Whether to loop the sound.
Bool
default:"false"
Whether to destroy the sound when finished.
Bool
default:"true"
Whether to play immediately after loading.
Void->Void
Callback when the sound finishes playing.
Void->Void
Callback when the sound finishes loading.
Promise<Null<FunkinSound>>
A promise that resolves to the loaded sound or
null if loading failed.playMusic
music/<key>/<key>-metadata.json if available.
String
required
The music key. Music is loaded from
music/<key>/<key>.ogg.FunkinSoundPlayMusicParams
required
Configuration object for music playback. See below for properties.
Bool
Returns
true if music started successfully, false if music was already playing or couldn’t start.FunkinSoundPlayMusicParams
Float
default:"1.0"
Initial volume for the music.
String
default:"''"
Suffix for the music file (e.g., “-erect” for alternate tracks).
Bool
default:"false"
Whether to override music if a different track is playing.
Bool
default:"false"
Whether to restart if the same track is already playing.
Bool
default:"true"
Whether the music should loop.
Bool
default:"true"
Whether to load and apply time signature changes from metadata.
PathsFunction
default:"MUSIC"
Which Paths function to use (
MUSIC or INST).PartialSoundParams
Parameters for partial loading (see
loadPartial).Bool
Whether the sound persists across state changes.
Void->Void
Callback when the music finishes.
Void->Void
Callback when the music finishes loading.
playOnce
String
required
The sound key/path.
Float
default:"1.0"
Playback volume (0.0 to 1.0).
Void->Void
Callback when the sound finishes.
Void->Void
Callback when the sound loads.
Bool
default:"false"
Bypass channel limits if
true.Null<FunkinSound>
Returns the sound instance or
null if loading failed.stopAllAudio
Bool
default:"false"
If
true, also stops the current music track.Bool
default:"false"
If
true, also stops sounds marked as persistent.setMusic
FlxG.sound.music).
FunkinSound
required
The sound to set as music.
Example Usage
Basic Sound Playback
Playing Music
Delayed Playback
Partial Loading
Notes
- Sounds with negative timestamps require the sound to be added to a scene with
add()for the countdown timer to work - The
importantflag should be used sparingly as it bypasses audio channel limits - Waveform data is cached after first access for performance
- The sound pool automatically recycles dead instances to reduce garbage collection
