Quantcast
Channel: Community | MonoGame - Latest topics
Viewing all articles
Browse latest Browse all 6821

Positioning a sprite if frame rate is low

$
0
0

@LEM wrote:

I use this parabolic logic when the sprite jumps. When the user clicks on the jump button, I set mVY = -300

int mVY = 0;   
public override void Update(GameTime theGameTime)
{
    Vector2 speed = Vector2.Zero;
    Vector2 direction = Vector2.Zero;

    if (mVY < 0)
    {
        speed.Y -= mVY;
        direction.Y = -1;
    }
    else
   {
        speed.Y += mVY;
        direction.Y = 1;
    }

    mVY += 8; 
    if (mVY > 300)  mVY = 300; // Limit maximum speed if falling

    Position += direction * speed * (float)theGameTime.ElapsedGameTime.TotalSeconds;

    ...
}

This code works ok when my game is running at 60fps, however when it's less than that the jumps are very high and slow. I thought that multiplying by theGameTime.ElapsedGameTime.TotalSeconds would fix the problem, but I must be missing something because it doesn't work properly.

Any ideas?

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 6821

Trending Articles