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
Mute this specific sound without affecting volume. When set to
true, the sound is silenced.Whether the sound is currently paused.
Returns
true if the sound is playing or scheduled to play (including negative timestamps).Lazily-loaded waveform data for this sound. Generated on first access and cached for subsequent use.
If
true, forcefully adds this sound’s channel to the playing sounds list even when the channel limit is reached. Use sparingly!The volume level (0.0 to 1.0).
Static Properties
A signal dispatched whenever the global volume changes.
Internal pool of FunkinSound instances for efficient recycling.
Methods
play
startTime values for delayed playback.
If
true, restarts the sound even if already playing.Time in milliseconds to start at. Negative values delay playback.
Time in milliseconds to stop at.
Returns the sound instance for method chaining.
pause
Returns the sound instance for method chaining.
resume
Returns the sound instance for method chaining.
togglePlayback
Returns the sound instance for method chaining.
clone
A new FunkinSound instance with cloned data.
Static Methods
load
The sound asset path or embedded sound resource.
Initial volume (0.0 to 1.0).
Whether to loop the sound.
Whether to destroy the sound when finished. Set to
false to reuse the instance.Whether to play immediately after loading.
Whether to keep the sound across state changes.
Callback when the sound finishes playing.
Callback when the sound finishes loading.
If
true, bypasses channel limits. Use sparingly!Returns the loaded sound, or
null if loading failed or channels are exhausted.loadPartial
The path to the sound file.
Start position as a percentage (0.0 to 1.0).
End position as a percentage (0.0 to 1.0).
Initial volume (0.0 to 1.0).
Whether to loop the sound.
Whether to destroy the sound when finished.
Whether to play immediately after loading.
Callback when the sound finishes playing.
Callback when the sound finishes loading.
A promise that resolves to the loaded sound or
null if loading failed.playMusic
music/<key>/<key>-metadata.json if available.
The music key. Music is loaded from
music/<key>/<key>.ogg.Configuration object for music playback. See below for properties.
Returns
true if music started successfully, false if music was already playing or couldn’t start.FunkinSoundPlayMusicParams
Initial volume for the music.
Suffix for the music file (e.g., “-erect” for alternate tracks).
Whether to override music if a different track is playing.
Whether to restart if the same track is already playing.
Whether the music should loop.
Whether to load and apply time signature changes from metadata.
Which Paths function to use (
MUSIC or INST).Parameters for partial loading (see
loadPartial).Whether the sound persists across state changes.
Callback when the music finishes.
Callback when the music finishes loading.
playOnce
The sound key/path.
Playback volume (0.0 to 1.0).
Callback when the sound finishes.
Callback when the sound loads.
Bypass channel limits if
true.Returns the sound instance or
null if loading failed.stopAllAudio
If
true, also stops the current music track.If
true, also stops sounds marked as persistent.setMusic
FlxG.sound.music).
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
