| name | fxgl-audio |
| description | Play and manage audio in FXGL — trigger one-shot sound effects, loop background music, control master and per-type volume, load sound and music assets, use the AudioPlayer service directly, and speak text via platform TTS. Use this skill when adding sound effects to game events, playing background music, implementing volume sliders, or integrating text-to-speech dialogue in a game.
|
| triggers | ["sound effect","background music","AudioPlayer","play sound","loopBGM","music volume","SFX","wav","mp3","text to speech","TTS","audio"] |
| compatibility | Java 17+, FXGL 21.x. TTS requires fxgl-intelligence module and platform TTS engine.
|
| category | fxgl/audio |
| tags | ["fxgl","java","javafx","audio"] |
| metadata | {"author":"fxgl-skills","version":"1.0","fxgl-version":"21.1"} |
| allowed-tools | ["Read","Write","Edit","Bash"] |
FXGL Audio System
Asset Placement
Audio files go in src/main/resources/assets/:
- Sounds →
assets/sounds/ — short clips (WAV recommended for low latency)
- Music →
assets/music/ — long tracks (MP3 or OGG for size efficiency)
Quickstart — DSL Shortcuts
FXGL.play("sounds/shoot.wav");
FXGL.loopBGM("music/theme.mp3");
FXGL.stopBGM();
FXGL.pauseBGM();
FXGL.resumeBGM();
Loading and Playing Manually
Sound jumpSound = getAssetLoader().loadSound("sounds/jump.wav");
Music themeMusic = getAssetLoader().loadMusic("music/theme.mp3");
getAudioPlayer().playSound(jumpSound);
getAudioPlayer().playMusic(themeMusic);
getAudioPlayer().loopMusic(themeMusic);
getAudioPlayer().stopMusic(themeMusic);
getAudioPlayer().pauseMusic(themeMusic);
getAudioPlayer().resumeMusic(themeMusic);
Volume Control
getSettings().setGlobalSoundVolume(0.8);
getSettings().setGlobalMusicVolume(0.5);
getAudioPlayer().setGlobalSoundVolume(0.7);
getAudioPlayer().setGlobalMusicVolume(0.4);
Sound s = getAssetLoader().loadSound("sounds/explosion.wav");
s.setVolume();
getAudioPlayer().playSound(s);
getAssetLoader().loadMusic();
bgm.setVolume();
getAudioPlayer().loopMusic(bgm);