Flash Experiment – Creating Rhythm (1/3)

July 6, 2009

Rock Band 2

The Preamble & Problem

Say you wanted to create a rhythm game in Flash along the lines of Guitar Hero, Rock Band, or, my favourite, Parappa the Rappa. You’d need a method of maintaining a beat.

Two main problems keep this in the realm of annoying.

  1. Flash can’t be trusted to keep a constant framerate.
  2. Flash can’t be trusted to fire a Timer() event at a consistent rate.

The framerate problem is well documented. Even if you set your movie to play at 30fps, what you get in the IDE and various browser players may vary by 5-10fps. This would mean a potential variation of 300ms per second. If we use a 60bpm song we’d miss a beat by up to 30% making for some pretty awful music.

The Timer() problem thankfully isn’t as bad ( as you’ll see, my solution heavily uses Timer() events). But it’s important to understand that you can’t trust the Timer() event to fire when it’s supposed to. I’ve found the Timer interval to actually fire a few ms slow. Not much, but it compounds over time and beats start sounding out of sync before the first bar is played.

Goals

Before I dive into my solution, let’s clarify the goals.

  1. A background music loop plays. This is just a simple .wav with a beat at 120bpm.
  2. We accurately keep track of whole notes so we can “snap” audio cues to be in sync with the background music loop.

This “snap-to-note” mechanic is how you make a player feel awesome in a rhythm game by giving them a margin of error. “Snap-to-note” will also allow other game sounds to synchronize with the base track.

Next up… Checking for a Pulse.

Leave a Comment

Previous post:

Next post: