Posted May 30, 2024 by templewulf
#godot #update #puzzle #sudoku
This week, we're bringing a couple of small touches of polish.
This update has been significantly less of a pain than some of the more recent devlogs. The signal architecture has been paying off in rearranging and reconnecting various nodes without having to rewrite code.
The hardest one was the `Next Song` feature. It uses the Godot AudioStreamRandomizer resource type to automatically randomize selecting an audio file from an array of files. That's not hard to write on your own, but it's usually a good idea to pick off-the-shelf parts for better support.
The problem with it was that the audio player checks to see if a request to play a new stream is for the currently playing stream. Since the resource file that contains references to all of the BGM is always the same, it was technically always playing the same resource and would never try randomizing again.
You'd think you could just stop and start it to circumvent that, but due to factors like fadeout times and deferred calls, it never finished a stream before the new play request came in. We solved it by simply padding out the call with enough time to clear it. These aren't mathematically derived times (that's how the feature got stuck never working!), but instead we just tested a variety of values until it worked consistently.
Once we found the solution, it was satisfyingly simple to put together with timers and signals.
if event.is_action_pressed("next_song"): SoundManager.stop_music(MUSIC_FADEOUT_TIME) get_tree().create_timer(MUSIC_NEXT_SONG_TIME).timeout.connect( func(): self.play_music() )
Overall, it's been a fun week to work in Godot!