-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudio.gd
More file actions
37 lines (31 loc) · 1.41 KB
/
Audio.gd
File metadata and controls
37 lines (31 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
extends Object
class_name Audio
const BUS_SOUNDS = "Sounds"
const BUS_VOICE = "Voice"
static var playNode:Node
static func _play_sound(sound: AudioStream, player, maxDistance:float = 10.0, theBus:String = BUS_SOUNDS):
player.stream = sound
player.autoplay = true
player.bus = theBus
if((player is AudioStreamPlayer2D) || (player is AudioStreamPlayer3D)):
player.max_distance = maxDistance
static func playSound(sound: AudioStream, maxDistance:float = 10.0, theBus:String = BUS_SOUNDS) -> AudioStreamPlayer:
var newPlayer := AudioStreamPlayer.new()
_play_sound(sound, newPlayer, maxDistance, theBus)
playNode.add_child(newPlayer)
newPlayer.finished.connect(func(): newPlayer.queue_free())
return newPlayer
static func playSound2D(node:Node2D, sound: AudioStream, maxDistance:float = 10.0, theBus:String = BUS_SOUNDS) -> AudioStreamPlayer2D:
var newPlayer := AudioStreamPlayer2D.new()
_play_sound(sound, newPlayer, maxDistance, theBus)
node.add_child(newPlayer)
newPlayer.finished.connect(func(): newPlayer.queue_free())
return newPlayer
static func playSound3D(node:Node3D, sound: AudioStream, maxDistance:float = 10.0, theBus:String = BUS_SOUNDS) -> AudioStreamPlayer3D:
if(maxDistance < 0.0):
maxDistance = 10.0
var newPlayer := AudioStreamPlayer3D.new()
_play_sound(sound, newPlayer, maxDistance, theBus)
node.add_child(newPlayer)
newPlayer.finished.connect(func(): newPlayer.queue_free())
return newPlayer