godotengine / godot-docs

Godot Engine official documentation
https://docs.godotengine.org
Other
3.61k stars 2.98k forks source link

AudioStreamPolyphonic not obvious how it works #9488

Open yankscally opened 4 weeks ago

yankscally commented 4 weeks ago

Your Godot version: 4.3 beta 1

Issue description:

When looking at AudioStreamPolyphonic, there is no code example. There should be one, because it took me a lot of digging and some luck to find out how it works.

extends AudioStreamPlayer
var polyphonic = AudioStreamPolyphonic.new()
var playback : AudioStreamPlaybackPolyphonic

var my_sound = load("res://my_sound.wav")

func _ready():
    stream = polyphonic
    play()
    playback = get_stream_playback() # you need to do this for it to work

func process():
    if Input.is_action_just_pressed("ui_accept"):
         playback.play_stream(my_sound, 0, 0, 1) # stream, volume, from, pitch 

URL to the documentation page (if already existing): it's AudioStreamPolyphonic, but there is also a page for the playback class. It would be good to include it at least once. https://docs.godotengine.org/en/stable/classes/class_audiostreampolyphonic.html

skyace65 commented 3 weeks ago

Please consider opening a pull request yourself to add that example to the documentation. The file you want to edit is in the main Godot repository here.

yankscally commented 3 weeks ago

done. I am happy to write more about audio stuff in the future