[C#] Maintaining a constant animation speed with changing FPS. Is it possible?

Started by stripe103, December 23, 2011, 12:22:59 pm

Previous topic - Next topic

stripe103

I'm trying to make a Super Mario World kind of copy myself in C# using the game library AGATELib. The thing is that it's FPS is changing between like 200 to 1000, but I want to have the animation speed to be constant(different between each block in this case) and the code I currently have updates the animation for example once every 10 frames, and if the fps change, the animation speed does too.

I'm not very experienced with making games like this and need help with it. Basically I need some kind of equation or something that makes me able to have the same animation speed.

This is the animation update method that all blocks use: ShowHide

Variables are:
private Sprite sprite;
private double animationSpeed;
private double frames = 0;
Code: Update method
public void MainUpdate()
        {
            if (frames > animationSpeed)
            {
                sprite.AdvanceFrame();
                frames = 0;
            }
            frames++;
        }


What can I do to make this work?

Regards
Stripe103

Blizzard

You should be able to access how much time has passed since the last frame has been rendered. Check their API reference. Multiply that time with your animation speed and your animations should have a constant speed regardless of frame rate.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

stripe103

Seems to have worked. I tried with the DeltaTime before, but I put it in the wrong place.

Anyway, I'll send you a PM or something if it don't work as it should, but for now, Thank you!