William Lew
William Lew

Reputation: 485

Acceleration using Game Time

I was wondering if there is any elapsed gametime method that I could add acceleration to a entity. I want to use something like XNA's elapsed gametime code. The amount of seconds that pass by through each frame is all I need to get acceleration working.

Upvotes: 0

Views: 569

Answers (1)

The Fiddler
The Fiddler

Reputation: 2794

If you are using GameWindow, you can use the FrameEventArgs from the UpdateFrame and RenderFrame events.

class MyGame : GameWindow
{
    double seconds;
    Vector3 position;

    protected override void OnUpdateFrame(object sender, FrameEventArgs e)
    {
        // e.Time is the elapsed time from the previous UpdateFrame event
        // in seconds
        seconds += e.Time;
        position = new Vector3(
            (float)Math.Cos(seconds),
            (float)Math.Sin(seconds),
            1.0f);
    }
}

Upvotes: 1

Related Questions