SFML community forums
Help => Graphics => Topic started by: mic4h on March 19, 2012, 07:14:33 pm
-
Hi! I'm new btw. Anyway, I have a pong clone copied virtually line-for-line from the "sfml game from scratch" tutorial (he calls it "Pang!"). The paddles and ball move very smoothly on my computer, but are very fast and too sensitive on my friend's computer. Position is updated as follows:
get time and call update():
float timeDelta = Game::GetWindow().GetFrameTime();
Update(timeDelta);
inside of update:
Update (float elapsedTime){
if (Game::GetInput().IsKeyDown(sf::Key::Right))
_velocity += 3.0f;
GetSprite().Move(_velocity * elapsedTime, 0);
}
My understanding was that this process effectively scales the speed by the framerate so that it doesn't matter how fast or slow a computer is-- the objects should always move around at the intended speed. This doesn't seem to be working though.
Thoughts?
-
Your problem is:
_velocity += 3.0f;
This line is executed every frame the player has the key pressed :)
Either assign a constant to "_velocity", or do something like:
_velocity += 3.0f * elapsedTime;
-
This should do the trick, but I still strongly suggest using a fixed timestep!
-
This should do the trick, but I still strongly suggest using a fixed timestep!
Could you elaborate on this? Why would you ALWAYS use a fixed timestep?