Last active
May 8, 2021 20:41
-
-
Save opyate/ac58d0a00ebb08cd846ea37d4b969a2c to your computer and use it in GitHub Desktop.
Global music for a Godot game, with fade-in if the song is made for looping (i.e. starts of loudly)
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 Node | |
func _ready(): | |
var fade_in = Tween.new() | |
add_child(fade_in) | |
var music = AudioStreamPlayer.new() | |
add_child(music) | |
var stream = load("res://assets/audio/music/song.ogg") | |
music.set_stream(stream) | |
music.pitch_scale = 1 | |
fade_in.interpolate_property(music, "volume_db", -80, 0, 4.0, Tween.TRANS_LINEAR, Tween.EASE_IN, 0) | |
fade_in.start() | |
yield(get_tree().create_timer(0.1), "timeout") | |
music.play() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment