Jump to content

Synchronizing music and game


morazor
 Share

Recommended Posts

Hello everyone.
So I've got this problem: I'd like to keep music and game synchronized.
 

The first thing I've tried is to synch music with game, but it just doesn't work because every time I restart the music it needs some time to decode and desynchs again in a loop. Also, IMO it's uglier to hear music skip instead of having the game skip some frames.

 

So I've tried the other way around: synchronizing game with music.

 

For now I'm keeping a variable that for every update sums game.time.physicsElapsedMS.
Then it checks this value with music.currentTime to see if they are in synch.

If they are not synched, the game speed is adjusted using game.time.slowMotion to let the game catch up with the music or vice versa. This doesn't work perfectly, but helps a bit.

I've also tried changing game.time.physicsElapsedMS and game seems to speed up or slow down according to the value I set, but it doesn't look very safe to do.

What's the best way to solve this problem?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...