41 lines
1.3 KiB
GDScript
41 lines
1.3 KiB
GDScript
extends StaticBody2D
|
|
|
|
var songs = [
|
|
"res://assest/music/chartreuse blues.ogg",
|
|
"res://assest/music/latino_accords_et_impro.ogg",
|
|
"res://assest/music/balade du grand nord.ogg",
|
|
]
|
|
|
|
var current_song = 0
|
|
|
|
func _ready() -> void:
|
|
$AnimationPlayer.play("play")
|
|
|
|
func _process(delta: float) -> void:
|
|
if $AudioStreamPlayer2D.get_playback_position() != 0:
|
|
GameState.float_thomas_music_position = $AudioStreamPlayer2D.get_playback_position()
|
|
var stream : AudioStream = $AudioStreamPlayer2D.stream
|
|
if stream:
|
|
var l = stream.get_length()
|
|
if is_zero_approx(l - GameState.float_thomas_music_position):
|
|
play_next_song()
|
|
|
|
func _on_load_from_game_state() -> void:
|
|
if GameState.float_thomas_music_position > 1:
|
|
$AudioStreamPlayer2D.seek(GameState.float_thomas_music_position)
|
|
print("resume from pause ", songs[current_song], "at ", GameState.float_thomas_music_position)
|
|
$AudioStreamPlayer2D.stream_paused = false
|
|
|
|
func play_next_song():
|
|
current_song += 1
|
|
if current_song == songs.size():
|
|
current_song = 0
|
|
print("play ", songs[current_song])
|
|
$AudioStreamPlayer2D.stream= load(songs[current_song]);
|
|
GameState.float_thomas_music_position = 0
|
|
$AudioStreamPlayer2D.play(GameState.float_thomas_music_position)
|
|
|
|
|
|
func _on_outside_unload_from_screen() -> void:
|
|
$AudioStreamPlayer2D.stream_paused = true
|