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

Update position in a low frame rate scenario

$
0
0

@LEM wrote:

I have a sprite moving horizontally from left to right. For each iteration I want to start decreasing the speed.
This works ok, and the sprite will stop at some point, however depending on the frame rate it won't always stop
at the same place. What's wrong with my code?

...
Vector2 Position;
Vector2 Speed;
...
Speed.X = 50;
...

public override void Update(GameTime theGameTime)
{
float time = (float) theGameTime.ElapsedGameTime.TotalSeconds;

        Position += Speed * time;

        Speed.X-=10; // Reduce speed for next iteration
        if ( Speed.X < 0 ) Speed.X = 0;

}

Posts: 9

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 6821

Trending Articles