Tip - How to have sounds play in sync. Even if the events that trigger them are not accurate.

HoneyTribeStudiosHoneyTribeStudios Member Posts: 1,792
Someone was asking me about having sounds play in sync for a rhythm game. Even if the player is not so accurate and you want the music to still sound good. So thought I may as well post it here and in the cookbook:

The example below is for 160 bpm. So each beat is 0.375 seconds and 4 beats is 1.5 seconds.


First play all your sounds silently at the start of the scene. This loads them into the RAM.

So when your object is touched have it trigger a boolean attribute. Let's call it self.trigger

Then you want another boolean attribute self.playMusic
And an index/integer attribute game.zero which is set to 0.

So the rule would be something like

When self.trigger = true
and game.zero = game.time%1.5

change self.playMusic to true

(Note: if you just want a short sound effect to trigger in sync instead of a short loop then you can change the game.time%1.5 to game.time%0.375)

Then you have a final rule:
When self.playMusic = true
Play Sound: myLoop

So somewhere, at the appropriate time for your gameplay you'll have to have self.trigger and self.playMusic turn to false so that the loop can be triggered again.

Method 2:

First play all your sounds silently at the start of the scene. This loads them into the RAM.

Set the volumes in the Play Sound behaviours with an integer attribute self.volume
Express it as self.volume/10.
Self volume is initially set to 0.

Then use a rule similar to method 1 to play them all at the same time at a specific time and have loop checked. So all loops are constantly playing in silence. This assumes your loops are good and all loop cleanly and seamlessly to the same tempo.

Then interpolate self.volume to a maximum of 10 when needed.
Sign In or Register to comment.