Open nonunknown opened 3 years ago
Here's what I use: https://github.com/Calinou/escape-space/blob/c151b264c622fcd823a2c43855b2a6f2d8bbe68f/autoload/sound.gd
To be fair, I think this should be solved at the core level by readding polyphony support.
@Calinou This one lets me play a lot of audios in short time? Also makes sense to be a core issue, in all my projects I had problem with audio! but until there a doc to at least give a north to people out there!
This one lets me play a lot of audios in short time?
Yes :slightly_smiling_face:
thank you very much!
@Calinou made a C# version of it, worked flawlessly thank you again!
using Godot;
using System;
public static class OSTManager
{
public static void PlaySFX(Node target, AudioStream stream, Vector2 position, float pitchScale = 1.0f) {
AudioStreamPlayer2D sfx = new AudioStreamPlayer2D();
target.GetTree().CurrentScene.AddChild(sfx);
if (position != null) sfx.GlobalPosition = position;
sfx.Stream = stream;
sfx.VolumeDb = 0;
sfx.PitchScale = pitchScale;
sfx.Play();
sfx.Connect("finished",sfx,"queue_free");
}
public static void PlaySFXPitched(Node target, AudioStream stream, Vector2 position) {
RandomNumberGenerator rng = new RandomNumberGenerator();
PlaySFX(target,stream,position,rng.RandfRange(.9f,1.7f));
}
}
4.0alpha has built-in polyphony support, but it can't be backported to 3.x since it relies on different AudioServer internals. I suppose this still needs to be documented on the manual page that mentions playing sounds in general.
https://github.com/Calinou/escape-space/blob/c151b264c622fcd823a2c43855b2a6f2d8bbe68f/autoload/sound.gd is short enough to include inline on the page, but we could also link to a maintained add-on in the asset library.
yeah thats the perfect solution!
Your Godot version: 3.2.4 RC1
Issue description: Altought the docs talk about how WAV file format can play thousands of it without any performance issue, the docs doesnt says how this can be archieved, I finally manage to found a tutorial from a user who did it right, but that is not begginer friendly and I couldnt understand it well too.
Maybe there's a better approach? In any case this should be documented, playing a lot of sounds in a little space of time is not simple!
Source Content
https://www.youtube.com/watch?v=DsAIrA9UE4E https://www.youtube.com/watch?v=3CFWlQzMthY
Source Code