mlpcardgame/Scenes/UI/BGMusic.gd
2019-06-03 01:35:31 +02:00

17 lines
No EOL
442 B
GDScript

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()