Tweak default music fade duration

This commit is contained in:
Alice Gaudon 2020-08-18 12:02:14 +02:00
parent 28b6d0fc7c
commit 1d0f1bae80

View File

@ -6,7 +6,7 @@ var animation_duration : float
var target_track : AudioStreamPlayer
var previous_tracks : Array
func play(music, offset=0, duration=2):
func play(music, offset=0, duration=1):
print('Play music: ' + music)
var path = "res://sounds/" + music + ".ogg"
if !File.new().file_exists(path):
@ -25,7 +25,7 @@ func play(music, offset=0, duration=2):
target_track.stream = stream
target_track.play(offset)
func fade_out(duration=2):
func fade_out(duration=1):
target_track = null
previous_tracks = get_playing_tracks()
fading = true
@ -57,9 +57,9 @@ func _process(delta):
var p = clamp(animation_time / animation_duration, 0, 1)
if target_track != null:
target_track.volume_db = lerp(-90, 0, clamp(p * 2, 0, 1))
target_track.volume_db = lerp(-90, 0, p)
for previous_track in previous_tracks:
previous_track.volume_db = lerp(0, -90, clamp((p * 2) - 1, 0, 1))
previous_track.volume_db = lerp(0, -90, p)
if p == 1:
fading = false