mlpcardgame/Scenes/Scripts/BGMusic.gd

24 lines
609 B
GDScript3
Raw Permalink Normal View History

2019-06-02 23:35:31 +00:00
extends AudioStreamPlayer
2019-07-06 00:15:43 +00:00
const LOW: float = -8.0;
const HIGH: float = 0.0;
2019-06-02 23:35:31 +00:00
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
2019-07-06 00:15:43 +00:00
play()
func set_volume(vol: float):
var idx := AudioServer.get_bus_index("BGM")
AudioServer.set_bus_volume_db(idx, vol)