Jaray Reeves
Jaray Reeves

Reputation: 23

Xna C# - Rhythm game music off sync when the window is active

I'm making a traditional rhythm game in XNA, and I have a simple formula that calculates the distance from the guide notes that a note has to be from the guide note relative to the time in which the note is designated to hit the guide note as well as speed of the note. The problem is that the notes pass the guide notes ~1-2 seconds earlier than designated. The note moves at 1 pixel a frame, and I noticed that when the window is active, the note moves a little faster than expected and passes the guide note early. When the window is inactive (I gave the focus to my task bar so that I was still able to see the game), the note arrives at the guide note exactly at the designated time. If you find that I am unclear, I will try to provide as much detail as possible! Thank you! I forgot to mention that FPS is also relative in the formula.

Upvotes: 2

Views: 777

Answers (1)

user1146887
user1146887

Reputation:

The reason why you are having syncing issues is the fact that your game is based off FPS, said so in the comments.

Use the GameTime class to manage your notes, since your frame rate can drop at anytime, usually through Garbage Collection.

And if there is anymore syncing issues, the MediaPlayer has a property called TimePosition which is a TimeSpan that indicates where the song position is.

I hope this helps.

Upvotes: 1

Related Questions