GMSync Documentation

The ultimate way to sync elements of your game to music.

GMSync provides a no-brainer approach to perfect music syncing in GMS 2.3+. It allows you to specify music note lengths to sync to, and works directly with track positions. This means it will never de-sync due to frame rate stutters or moving the window around. You can use this library to perfectly sync audio to game elements and create basic rhythm games.

A full example is available when importing the package into your project that showcases all of the features discussed below.

Note: The 2.0.0 update is incompatible with previous versions since it is a complete rewrite of the project. Documentation for older versions is included directly the script asset.

Quick start

Here's a complete example of a simple GMSync setup:

Create event
Step event

First we use sync_init() to setup data related to our track. The first argument is the BPM for the track, and the second argument is the delay until song begins, in seconds. This is only needed if your music track doesn't begin the moment you play it. This isn't common for game development, but if for some reason your track has some empty space in the front then you can use this value to account for that. Be sure that your delay is in seconds, with up to three decimal places for milliseconds for the best timing. Lastly, we play the audio we're going to sync to.

Once this has been setup, we call sync_update_all() at the start of our step event, passing in our sync data and a reference to the music we're playing. We only need to update once per frame, and after that we can call sync_check() as many times as we need to see if the current frame lines up with the pulse of the music. In the above example, we're checking if a quarter note pulse/beat has landed on this frame.

Checking input

If you want to make a rhythm game that requires the player to press an input to the beat of the music, you can use the sync_check_input() function:

Step event

In the above example, we use sync_check_input() to get the distance to the nearest beat. This is provided as a percantage, with a value of 0 being exactly on the beat and 1 being as far away from the beat as possible. It accepts an argument to account for input latency (here expressed as 0.2 seconds). Here we compare the result against 0.3, and if the result is below that (meaning we are less than 30% of a total beat's length away from the previous or next beat) then we consider the beat as being "hit". Otherwise, it's a "miss" because we didn't do well enough in our timing.

License & Credits

GMSync (and all files included in the demo) unless otherwise specified are provided as-is for you to use freely in your projects.

Do not sell or redistribute. Emoji sprites used in the demo are sourced from this fork of twemoji and may not be re-used without attribution.