mlpcardgame/Scenes/Scripts/BGMusic.gd
2019-07-06 02:15:43 +02:00

24 lines
No EOL
609 B
GDScript

extends AudioStreamPlayer
const LOW: float = -8.0;
const HIGH: float = 0.0;
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()
func set_volume(vol: float):
var idx := AudioServer.get_bus_index("BGM")
AudioServer.set_bus_volume_db(idx, vol)