17 lines
442 B
GDScript3
17 lines
442 B
GDScript3
|
extends AudioStreamPlayer
|
||
|
|
||
|
func load_music(name: String):
|
||
|
# Calculate track path
|
||
|
var path := "res://Music/%s.ogg" % name
|
||
|
# Only load music if the track exists
|
||
|
var file := File.new()
|
||
|
if not file.file_exists(path):
|
||
|
return
|
||
|
var ogg_file = File.new()
|
||
|
ogg_file.open(path, File.READ)
|
||
|
var bytes = ogg_file.get_buffer(ogg_file.get_len())
|
||
|
var bgmstream = AudioStreamOGGVorbis.new()
|
||
|
bgmstream.data = bytes
|
||
|
stop()
|
||
|
stream = bgmstream
|
||
|
play()
|