79 lines
1.7 KiB
GDScript
79 lines
1.7 KiB
GDScript
extends Tween
|
|
|
|
const fadeMusicTime = 0.8;
|
|
const lowVolume = - 80;
|
|
const defaultVolume:float = 0.0;
|
|
var bgmStream:AudioStreamPlayer;
|
|
|
|
var darkChild:Sprite;
|
|
|
|
var isStoping = false
|
|
|
|
func _ready():
|
|
bgmStream = self.get_child(0);
|
|
bgmStream.bus = "SFXforBGM";
|
|
|
|
func PlayBGM(bgmPath):
|
|
isStoping = false
|
|
if self.is_active():
|
|
self.remove_all()
|
|
|
|
|
|
bgmStream.volume_db = lowVolume;
|
|
bgmStream.stream = load(bgmPath);
|
|
|
|
if bgmPath == "res://resources/audio/sfx/Rain Loop.ogg" and bgmStream.stream.loop_mode == 0:
|
|
print("loop rain fuck!")
|
|
bgmStream.stream.set_loop_mode(1);
|
|
|
|
|
|
var _temp = self.interpolate_property(bgmStream, "volume_db", lowVolume, defaultVolume, fadeMusicTime, Tween.TRANS_EXPO, 0)
|
|
bgmStream.play(0.0);
|
|
_temp = self.start();
|
|
|
|
func StopBGM():
|
|
|
|
var _temp = self.interpolate_property(bgmStream, "volume_db", defaultVolume, lowVolume, fadeMusicTime, Tween.TRANS_LINEAR, 0)
|
|
isStoping = true
|
|
_temp = self.start();
|
|
yield (self, "tween_all_completed")
|
|
|
|
|
|
func ChangeBGM(bgmPath2):
|
|
isStoping = false
|
|
if self.is_active():
|
|
self.remove_all()
|
|
if (bgmStream.stream.resource_path != bgmPath2):
|
|
StopBGM();
|
|
yield (self, "tween_all_completed")
|
|
PlayBGM(bgmPath2);
|
|
else :
|
|
PlayBGM(bgmPath2);
|
|
|
|
func PlayBGMNoFade(bgmPath):
|
|
isStoping = false
|
|
if self.is_active():
|
|
self.remove_all()
|
|
|
|
|
|
bgmStream.stream = load(bgmPath);
|
|
|
|
if bgmPath == "res://resources/audio/sfx/Rain Loop.ogg" and bgmStream.stream.loop_mode == 0:
|
|
print("loop rain fuck!")
|
|
bgmStream.stream.set_loop_mode(1);
|
|
|
|
|
|
|
|
bgmStream.play(0.0);
|
|
|
|
|
|
func ChangeBGMNoFade(bgmPath2):
|
|
isStoping = false
|
|
if self.is_active():
|
|
self.remove_all()
|
|
if (bgmStream.stream.resource_path != bgmPath2):
|
|
StopBGM();
|
|
yield (self, "tween_all_completed")
|
|
PlayBGMNoFade(bgmPath2);
|
|
else :
|
|
PlayBGMNoFade(bgmPath2);
|