Sync music with the gameplay

I’m trying so sync the sound “ouch.wav” with “kinda_epik_bossbattle_theme.wav”. The thing is that it doesn’t sync, even if I have the BPM set correctly (the BPM is 86.61). Any idea on how to make this sync better?

I guess it’s a matter of finding the perfect number for the timer. :person_shrugging:
Not sure how we can help.

1 Like

Why not use a sound app to create a song the same length as “kinda_epik_bossbattle_theme.wav”, and position the ouch.wav at the right intervals? Preload both pieces, and play them at the same time.

You may need to add a leading empty space to “kinda_epik_bossbattle_theme.wav” to allow for the first two plays of “ouch.wav”.

1 Like
  • Convert the BPM to a length of time (fraction of seconds)
  • Create a beat counter and set it to zero
  • Play your sound on a channel
  • Read the current offset on that channel
  • Divide the offset by the BPM length and truncate, and if it’s greater than the beat counter then play the sound and set the beat counter to the truncated dividend.
  • repeat

Right… Mind explaining me how to do it using the action/condition editor? :sweat_smile:

the closest I got to without de-syncing was 82.00000010. It seems that the 0s at the end also matter. It seems impossible to accurately determine the right number.

I see, then @MrMen 's idea sounds good (= easier than @krunkster 's :sweat_smile: )

1 Like

I used the “ouch.wav” file to see how it syncs because I actually want the scene background to change to a certain colour every 1/4th of a measure. So that’s why I am trying to make it sync with the ouch.wav file first

I didn’t think my logic was too complicated :sweat_smile:

I coded up a quick example:

The reason you want to base your logic on the song offset is because sometimes the game may slow down or your FPS might change, so you have to sync to the song.

Oh I don’t think Liluo shares the code, so here’s a zip:

1 Like

i requested file access for the google drive :slight_smile:

my email is and because i need access to the google drive file

I updated permissions on the link to give access to anyone.

1 Like

Interesting, can you tell me more? I’m making a rythm game, but whenever my fps change, the objects will not get to the position in perfect time, i found this and i got interested

If a deviation in FPS affects the game, then you should probably look into using TimeDelta().

1 Like

Thank you, imma check it out