Sign in to follow this  
etftw

Timing issues

Recommended Posts

Hey, I have been working on a prototype for a couple of weeks now in XNA which is similar in style to Guitar Hero in which you have sprites moving down the screen and the user must press them once they reach their destination. The problem however is that while the sprites are reaching their destination initially on time it slowly goes out of time as time goes on, I believe this could be due to the odd frame being lost (it only sees a 1fps drop every now and again) in the process possibly as the positioning does assume that the sprites will move 60 times per second. I am currently using the fixed timestep mode at the moment to limit the FPS to 60 and from what I have read using this also trys to recover lost frames. Can anyone recommend some online reading material that may help me overcome this problem? Thanks

Share this post


Link to post
Share on other sites
What I'd suggest to fix it is instead of calculating the position of the sprites based on the frame number, calculate them from the time elapsed since starting the song. That can either be retrieved from the audio playback system, or with a standard timer.

For example, assuming horizontal scrolling, you want something like:

MySprite.x = (SpriteSpeedInPixelsPerSecond * (TimeOfSprtiteInSong - TimeSinceSongStarted)) / TimerFrequency;

Share this post


Link to post
Share on other sites
Quote:
Original post by Adam_42
What I'd suggest to fix it is instead of calculating the position of the sprites based on the frame number, calculate them from the time elapsed since starting the song. That can either be retrieved from the audio playback system, or with a standard timer.

For example, assuming horizontal scrolling, you want something like:

MySprite.x = (SpriteSpeedInPixelsPerSecond * (TimeOfSprtiteInSong - TimeSinceSongStarted)) / TimerFrequency;


Hey,

Thanks for the reply, I am actually doing something similar to that at the moment except instead of specifying the speed in pixels per second I am specifying how much it moves every frame and then multiplying by 60 like this:

sprite.y = destination.y + ( ( speedPerFrame * 60 ) * ( timeTheSpriteShouldReachDestination - theTotalAmountOfSecondsElapsedInGame ) )

If I'm correct wouldn't using the algorithm you suggested result in the same thing?

The strange thing is when testing on the PC it works but on the 360 it seems to gradually go out of time.

I threw in a method to synchronise it every second as well so that all the sprites are where they should be just incase they have fallen behind with any loss of frames.

This really is one I just can't get my head around, I have spent days on end trying to figure it out.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this