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?
SFML Framerate Help
Moderator: Coders of Rage
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: SFML Framerate Help
Base velocity on time, not frame. No idea how to get the current tick in SFML, but it shouldn't be too difficult.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?
Random link from Google, you'll probably want to search time-based movement for more info.
http://peterstuifzand.nl/gameprog_3.html
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: SFML Framerate Help
use sf::Window::SetFramerateLimit() or sf::Window::UseVerticalSync()
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
-
- Chaos Rift Regular
- Posts: 173
- Joined: Thu Feb 11, 2010 9:46 pm
- Trimmy
- Chaos Rift Newbie
- Posts: 22
- Joined: Thu Aug 05, 2010 1:16 am
- Current Project: A Game
- Favorite Gaming Platforms: PS3, PC ( Mac OS )
- Programming Language of Choice: C++
- Location: New Zealand
- Contact:
Re: SFML Framerate Help
You should make things changed based on time, so as a simple example something like:
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.
Code: Select all
player.pos.x += player.hspeed * timediff;
My Programming Projects:http://www.youtube.com/user/TrimmyS
- GR33B
- Chaos Rift Newbie
- Posts: 17
- Joined: Fri Nov 14, 2008 3:33 pm
- Current Project: Project Crimson
- Programming Language of Choice: C#
- Location: Virginia
- Contact:
Re: SFML Framerate Help
Thanks, works like a charm now!Trimmy wrote:You should make things changed based on time, so as a simple example something like: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.Code: Select all
player.pos.x += player.hspeed * timediff;