How does the ElapsedGameTime work so that a variable dependent on it doesn’t increase as the game goes on? For example, this method:
private void Keyboard(GameTime gameTime)
{
float rotXZ = 0;
float turningSpeed = (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f;
turningSpeed *= 1.6f * gameSpeed;
KeyboardState keyState = Keyboard.GetState();
if (keyState.IsKeyDown(Keys.Right))
rotXZ += turningSpeed;
if (keyState.IsKeyDown(Keys.Left))
rotXZ -= turningSpeed;
}
I got it from a source that explains that we use ElapsedGameTime so the rotation speed is the same for fast/slow computers, but I don’t see how this works?
Thanks
It works because the rotation will increase relative to the time since the last frame instead of the number of updates.
On a better computer there will be more updates in the same amount of time than on a slow computer.