Right now I’m starting to work on a simple rhythm platformer for Android and PC. The game world will update according to the beat of the music. At first I tried updating twice a second by having an int increment each update until it got to thirty, like this—
void Update()
{
counter++;
if (counter == 30)
{
counter = 0;
Beat():
}
}
—and for the most part, that works. However, I set it to play a tone each time counter reached thirty, and then listened to it for a while, and noticed little inconsistencies in the spacing between notes. There was other code involved in the update method, too, but nothing too drastic.
So I was wondering, what’s the best way to go about this? One way I thought of was to use some sort of Timer independent of the Update method, and then have the Update method spin until the timer interrupts. That would probably mean increasing how frequently Game1.Update() is called. How do I do that?
Also, if I were to use one of the .NET timers, would Stopwatch or Timer be more accurate?