mlpcardgame/Scenes/Scripts/BGMusic.gd

17 lines
442 B
GDScript3
Raw Normal View History

2019-06-02 23:35:31 +00:00
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()