Created
April 4, 2023 13:26
-
-
Save brettchalupa/13453fb9e63828b1d0024b9706444ff3 to your computer and use it in GitHub Desktop.
Playing Music and Sound Effects in Godot 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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