Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: strange and sharp object movement, due to SetFramerateLimit  (Read 1624 times)

0 Members and 1 Guest are viewing this topic.

excentio

  • Newbie
  • *
  • Posts: 21
    • View Profile
strange and sharp object movement, due to SetFramerateLimit
« 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

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: strange and sharp object movement, due to SetFramerateLimit
« Reply #2 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/

excentio

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: strange and sharp object movement, due to SetFramerateLimit
« Reply #3 on: March 04, 2015, 06:30:34 pm »
thanks guys, btw, what is
integrate( state, t, deltaTime );
in that code ?

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: strange and sharp object movement, due to SetFramerateLimit
« Reply #4 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/

excentio

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: strange and sharp object movement, due to SetFramerateLimit
« Reply #5 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 :)

 

anything