Skip to content

Instantly share code, notes, and snippets.

@brettchalupa
Created April 4, 2023 13:26
Show Gist options
  • Save brettchalupa/13453fb9e63828b1d0024b9706444ff3 to your computer and use it in GitHub Desktop.
Save brettchalupa/13453fb9e63828b1d0024b9706444ff3 to your computer and use it in GitHub Desktop.
Playing Music and Sound Effects in Godot 4
extends Node2D
@onready var pickup_sfx:AudioStreamPlayer = $PickupSfx
@onready var music:AudioStreamPlayer = $Music
func _on_play_sfx_pressed() -> void:
pickup_sfx.play()
var music_pos = 0.0
func _on_play_music_pressed() -> void:
if music.playing:
music_pos = music.get_playback_position()
music.stop()
$PlayMusic.text = "ResumeMusic"
else:
music.play(music_pos)
$PlayMusic.text = "PauseMusic"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment