Music sync events

D

Dioramos

Guest
So, if i need to make bossfight with music synchronized attacks (every try the same timings), how should i do this? I know i must use "audio_sound_get_track_position", but i can't make it work properly.
What should the code look like if i need to spawn 1 attack on 3 second, 2 attack on 5 second, N attack on X second of music track?
 

trentallain

Member
So, if i need to make bossfight with music synchronized attacks (every try the same timings), how should i do this? I know i must use "audio_sound_get_track_position", but i can't make it work properly.
What should the code look like if i need to spawn 1 attack on 3 second, 2 attack on 5 second, N attack on X second of music track?
If you know the BPM, you could set an alarm (or timer) to update once every BPM / 60 / game speed (I think). And then count how many beats (make sure to floor it) have passed to then do an attack. Just start this BPM timer as soon as you start a song.

Edit: this will appear much more in time compared to seconds passed.
 

SoVes

Member
You don't want to use a timer. Music plays independent from framerate so it will go offsync.
 

TsukaYuriko

☄️
Forum Staff
Moderator
Linking this to game speed (e.g. alarms) will not work - if the game lags, everything will be thrown off sync. Keep in mind that you can specify fractions of a second, so it's by far not as inaccurate as it sounds. (I'd still prefer if those functions operated on samples, but ah well.)

I'd stick with the track position functions, keep track of when the last attack was triggered (in seconds), and if the desired interval step has passed, trigger a new attack. The mod operator could be useful here for making something happen every n seconds, and the floor function can be used to compute this in whole seconds instead of fractions.
 
Top