tutorials/audio/sync_with_audio #217
Replies: 2 comments 2 replies
-
Quick word of warning from a rhythm game developer: |
Beta Was this translation helpful? Give feedback.
-
Here's a handy function code to convert seconds to crotchets (AKA beats/quarter notes): # This dictionary stores each time the bpm changes in the song. It's in dictionary format since I wrote it to support custom levels stored in .json files. It does not support gradual BPM changes.
var bpm_changes:Array[Dictionary] = [ # Example value, sets the BPM to 120 at beat one and nothing else
{
"Crotchet":1.0, # The beat that the BPM changes
"BPM":120, # The BPM it changes to
},
]
func seconds_to_crotchet(seconds:float) -> float:
var remaining_seconds := seconds # I don't think this is necessary in gdscript, but just to be safe
var last_bpm := 100.0 # arbitrary value in case no bpm is set on beat 1
var last_crotchet := 1.0
var total_crotchets := 1.0
for change in bpm_changes:
var full = remaining_seconds*last_bpm/60
if full >= change["Crotchet"]:
var diff = change["Crotchet"]-last_crotchet
total_crotchets += diff
remaining_seconds -= diff/last_bpm*60
last_bpm = change["BPM"]
last_crotchet = change["Crotchet"]
else:
break
total_crotchets += remaining_seconds*last_bpm/60 + 1
return total_crotchets |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
tutorials/audio/sync_with_audio
Introduction: In any application or game, sound and music playback will have a slight delay. For games, this delay is often so small that it is negligible. Sound effects will come out a few millise...
https://docs.godotengine.org/en/stable/tutorials/audio/sync_with_audio.html
Beta Was this translation helpful? Give feedback.
All reactions