0 votes

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?

asked Mar 31, 2019 in Engine by Lapsyy (19 points)

2 Answers

0 votes

One way of doing it would be to add a [signal][1] for the finished event, 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

Hope this helps :-)

answered Mar 31, 2019 by GameVisitor (834 points)
+1 vote

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.

answered Mar 31, 2019 by twinpixel (185 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.