Loading...
Loading...
Import audio files and use AudioStreamPlayer nodes to add immersive sound to your game.
Import your audio files. Drag .wav or .ogg files into your project's FileSystem (create an 'audio' folder for organization). Godot supports WAV, OGG, and MP3 formats. OGG is recommended for music (smaller file size), WAV for sound effects (better quality).
For background music: Add an 'AudioStreamPlayer' node to your main scene or create a dedicated 'Music' scene. In the Inspector, find the 'Stream' property and click the dropdown to select your music file. Enable 'Autoplay' if you want it to start immediately.
For sound effects: Add 'AudioStreamPlayer' nodes as children of objects that need sound (buttons, player character, enemies). Set their 'Stream' property to the appropriate sound effect. Unlike music, these usually shouldn't autoplay.
Play sound effects via code. In your script, get the node: `var sfx = $AudioStreamPlayer`. Play it with: `sfx.play()`. For example, in a button's pressed signal: `func _on_Button_pressed(): $ClickSound.play()`. For the player, call jump_sfx.play() when they jump.
Control volume and settings. Add an AudioBus for music and another for SFX (Project → Project Settings → Audio). Assign each AudioStreamPlayer to the appropriate bus. Create a settings menu with HSlider nodes to control bus volumes using `AudioServer.set_bus_volume_db(bus_index, volume_db)`.