Jump to content

Synchronizing music and game


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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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