Topic was automatically imported from the old Question2Answer platform.
Asked By
Lapsyy
How do i play multiple sounds in quick succession without one overlapping the other?
i have a global sfx player but it has only 1 AudioStreamPlayer. I searched the internet and found polyphony but it is only for godot 2. is there something similar to polyphony for godot 3?
One way of doing it would be to add a [signal][1] for the finishedevent, ex:
func _on_AudioStreamPlayer_finished():
print( "Audio finished, start the next one logic")
#your logic to play the next one or a random one here...
pass
To enable polyphony for AudioStreamPlayers I have added the following script:
#helper for multiple audio stream playback
extends AudioStreamPlayer2D
func play( from_position=0.0 ):
if !playing:
.play(from_position)
else:
var asp = self.duplicate(DUPLICATE_USE_INSTANCING)
get_parent().add_child(asp)
asp.stream = stream
asp.play()
yield(asp, "finished")
asp.queue_free()
It uses polymorphism to override the AudioStreams play()-function and instantiate a new player. This also works for audio tracks in the AnimationPlayer.