Build a Rhythm Game in GameMaker: The Beat Sync Tutorial
120 BPM. That's the tempo of your average pop song, and the foundation of every rhythm game from Dance Dance Revolution to Crypt of the NecroDancer. But syncing game logic to a beat is harder than tapping your foot. Ross Manthorp and Topher Anselmo just published a deep-dive tutorial on the GameMaker blog that breaks down the math, the code, and the gotchas. If you've ever wanted to make a rhythm game—or just add some music-reactive flair to your project—this is the blueprint.
Here's the thing: most rhythm game tutorials stop at "play a song and check the track position." That works for a single cue, like a door opening at 10.5 seconds. But reacting to every beat? That requires understanding the difference between a timestamp and a recurring pulse. The tutorial walks you through the exact math: 60 / BPM = beat_length. With that, you can calculate where every beat lands in a song. But the real trick is dealing with frame timing.
Why Most Beat Detection Code Fails
Your game runs at 60 frames per second. Each frame takes about 16 milliseconds. A beat can happen between frames. So checking _current_track_position % beat_length == 0 will miss most beats. The fix is elegant: track the "progress" of the current beat using modulo, then compare it to the previous frame's progress. If the progress wraps around (from nearly 1 back to 0), a beat happened. That's the core logic.
The tutorial includes a working example: an object that squishes on every beat using image_yscale = 1.1 and image_xscale = 0.9, then lerps back to normal. It's the kind of polish that makes a game feel alive. The code is clean and ready to drop into a GameMaker project.
From Beat Detection to Player Input
Once your game can detect beats, the next step is letting the player react to them. The tutorial adds space bar input with a timing window. The key variable is _distance_to_beat, calculated as min(_beat_pos, 1 - _beat_pos). This gives a normalized distance to the nearest beat (0 to 1). If the player presses within 0.3 (30% of the beat length), it's a "Good." Within 0.1, it's a "Perfect." This is exactly how BPM: BULLETS PER MINUTE handles its gunplay.
Two practical corrections are included: input latency and song offset. The tutorial suggests subtracting 200ms from the track position to account for the delay between pressing a key and the game registering it. It also handles songs with silence at the start by subtracting an offset and using max(0, ...) to avoid negative values. These are the kind of fixes that separate a prototype from a shippable game.
What's Next
The tutorial wraps up with a pointer to a free GameMaker asset called GMSync on itch.io, which packages all of this into a single set of functions. If you'd rather not write the beat detection from scratch, it's a one-click download. The asset includes a complete example game, so you can see the system in action before adapting it to your own project.
Rhythm games are a genre that rewards precision and polish. With this tutorial, you've got the math, the code, and the edge cases covered. The rest is just making it fun.






Comments (0)
Loading comments…