// This is delta time to keep things straight for movement.
elapsedThisFrame = (float)(gameTime.ElapsedGameTime.TotalSeconds);
It’s easier to test by just turning off fixed time stamp all together and run at mega speed then turning it back on.
Alternately you can do the following.
now = gameTime.TotalGameTime.TotalSeconds;
elapsed = (double)(now - last);
last = now;
Similar to what the fps class below is doing but cutting out the message alarm trigger.
public class BasicFps
{
private double frames = 0;
private double updates = 0;
private double elapsed = 0;
private double last = 0;
private double now = 0;
public double msgFrequency = 1.0f;
public string msg = "";
/// <summary>
/// The msgFrequency here is the reporting time to update the message.
/// </summary>
public void Update(GameTime gameTime)
{
// I do this because i usually want to get the time now.
// As well as count the updates draws ect.
now = gameTime.TotalGameTime.TotalSeconds;
elapsed = (double)(now - last);
if (elapsed > msgFrequency)
{
msg = " Fps: " + (frames / elapsed).ToString() + "\n Elapsed time: " + elapsed.ToString() + "\n Updates: " + updates.ToString() + "\n Frames: " + frames.ToString();
elapsed = 0;
frames = 0;
updates = 0;
last = now;
}
updates++;
}
public void DrawFps(SpriteBatch spriteBatch, SpriteFont font, Vector2 fpsDisplayPosition, Color fpsTextColor)
{
spriteBatch.DrawString(font, msg, fpsDisplayPosition, fpsTextColor);
frames++;
}
}
Define calculations.
(can’t see what your engines calculations are internally from that code)
Speed is a scalar for directional acceleration, so is the delta. Normally you can multiply the speed by the delta by the direction of motion to alter your players position.
If you are using some acceleration to change your speed like to ramp it up over time.
Then you could apply it to that instead.
As shown in my code, I use velocity to gradually make the character go faster until it reaches a maximum. I check if adding the velocity would make it go above the maximum. Would I use delta in that check?
but isn’t it kind of weird to turn only if velocity is below zero
As well not be able to accelerate if its below zero ?
You should probably keep your turn logic and acceleration logic seperated.
Basically what I had there was if you’re pressing a button to go one way, but you’re currently going the other, it speeds up the velocity a bit to make a faster turn. I removed that because the speed boost was very visible on higher fps, and wasn’t really necessary anyway.