SFML community forums

Help => Graphics => Topic started by: excentio on March 04, 2015, 06:08:41 pm

Title: strange and sharp object movement, due to SetFramerateLimit
Post by: excentio on March 04, 2015, 06:08:41 pm
Hello guys, I have a problem, as I know, SetFramerateLimit calls Sleep() to keep game framerate probably constant, but here's the problem, when I use
int main() {
RenderWindow Window(VideoMode(1024,768), "Window");
Window.setFramerateLimit(60);

RectangleShape rs;
rs.setSize(Vector2f(50,50));
rs.setPosition(0,0);

while(Window.isOpen()) {
rs.move(5,0);
Window.draw(rs);
Window.display();
Window.clear();
}
return 0;
}
 

that rectangle is moving very sharply every random frame and it can also move a bit back, or a bit forward, I don't know how to fix this :c
Title: Re: strange and sharp object movement, due to SetFramerateLimit
Post by: zsbzsb on March 04, 2015, 06:29:00 pm
http://gafferongames.com/game-physics/fix-your-timestep/
Title: Re: strange and sharp object movement, due to SetFramerateLimit
Post by: Jesper Juhl on March 04, 2015, 06:29:19 pm
You should make your updates independent of the actual time between frames.
I recommend reading this: http://gafferongames.com/game-physics/fix-your-timestep/
Title: Re: strange and sharp object movement, due to SetFramerateLimit
Post by: excentio on March 04, 2015, 06:30:34 pm
thanks guys, btw, what is
integrate( state, t, deltaTime );
in that code ?
Title: Re: strange and sharp object movement, due to SetFramerateLimit
Post by: Jesper Juhl on March 04, 2015, 06:42:12 pm
See the previous article (that's also linked from the one we pointed you at): http://gafferongames.com/game-physics/integration-basics/
Title: Re: strange and sharp object movement, due to SetFramerateLimit
Post by: excentio on March 04, 2015, 06:54:36 pm
See the previous article (that's also linked from the one we pointed you at): http://gafferongames.com/game-physics/integration-basics/
oh, thanks, that answered many of my questions :)