Page 1 of 1
SFML Framerate Help
Posted: Sun Aug 15, 2010 8:09 pm
by GR33B
Hey all, I'm working on a tile engine, and have just migrated from XNA to SFML, because XNA hogs resources like a boss and I don't like the way it handles content loading.
Anyway, the switch was relatively simple, and gave me a huge boost in performance (XNA version was getting ~50fps on integrated graphics, SFML version is getting 100+ fps), so it's awesome so far. However, with this boost in framerate I encountered a problem: my game runs too fast, as in, the speed that things in-game happen is directly correlated to the framerate. Because at 50fps characters were walking, but at 100+ fps, characters are practically sprinting.
So how can I separate the framerate from the speed of gameplay, without limiting the framerate?
Re: SFML Framerate Help
Posted: Sun Aug 15, 2010 9:01 pm
by dandymcgee
GR33B wrote:Hey all, I'm working on a tile engine, and have just migrated from XNA to SFML, because XNA hogs resources like a boss and I don't like the way it handles content loading.
Anyway, the switch was relatively simple, and gave me a huge boost in performance (XNA version was getting ~50fps on integrated graphics, SFML version is getting 100+ fps), so it's awesome so far. However, with this boost in framerate I encountered a problem: my game runs too fast, as in, the speed that things in-game happen is directly correlated to the framerate. Because at 50fps characters were walking, but at 100+ fps, characters are practically sprinting.
So how can I separate the framerate from the speed of gameplay, without limiting the framerate?
Base velocity on time, not frame. No idea how to get the current tick in SFML, but it shouldn't be too difficult.
Random link from Google, you'll probably want to search time-based movement for more info.
http://peterstuifzand.nl/gameprog_3.html
Re: SFML Framerate Help
Posted: Sun Aug 15, 2010 9:02 pm
by Ginto8
use sf::Window::SetFramerateLimit() or sf::Window::UseVerticalSync()
Re: SFML Framerate Help
Posted: Sun Aug 15, 2010 9:08 pm
by X Abstract X
Re: SFML Framerate Help
Posted: Sun Aug 15, 2010 11:58 pm
by Trimmy
You should make things changed based on time, so as a simple example something like:
Code: Select all
player.pos.x += player.hspeed * timediff;
Where timediff is the time difference between the current frame and the last frame that way the player will move the same speed no matter what the frame-rate is.
Re: SFML Framerate Help
Posted: Tue Aug 17, 2010 1:56 am
by GR33B
Trimmy wrote:You should make things changed based on time, so as a simple example something like:
Code: Select all
player.pos.x += player.hspeed * timediff;
Where timediff is the time difference between the current frame and the last frame that way the player will move the same speed no matter what the frame-rate is.
Thanks, works like a charm now!