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

Author Topic: Controlling Game Speed on Different Computers  (Read 4905 times)

0 Members and 1 Guest are viewing this topic.

Solluxx

  • Newbie
  • *
  • Posts: 19
    • View Profile
Controlling Game Speed on Different Computers
« on: January 11, 2013, 06:06:47 am »
Hello there. I know this is a topic that is talked about a lot but I couldn't find too much about it in relation to SFML 2.0. So basically I just want to control the speed of my game so that it runs the same(and smoothly) on all machines. Right now my object moves at slightly different speeds depending on how fast my comp is running. I know about FrameLimiter but this only limits the amount of frames that are drawn it doesn't control game speed.

so I need...

Gameloop()
{
Input();
Update();
//do some check here
Draw();

//The Thinking functions need to be executed a certain number of times per second on every computer
//as long as these thinking function are caught up draw away!(within 60 fps)

}
 

I want to make it clear that I don't want a "velocity" fix. I really don't like this change in velocity depending on time solution. I would much rather have a fixed "time step"(as I've seen cleverly named in other posts) to my entire program.

So are there any functions or posts you could point me to to get this figured out? I don't need the logic so much as the code and syntax. I can figure it all out from there. :)

Thanks for any help you can give!
(Hopefully other people need this too, or don't know they need it till now ;) )



edit: I found this article http://www.koonsolo.com/news/dewitters-gameloop/ which gave me all the info I need gl!
« Last Edit: January 12, 2013, 07:39:10 am by Solluxx »

cire

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Re: Controlling Game Speed on Different Computers
« Reply #1 on: January 11, 2013, 06:35:34 am »
There is a lot of information about this out in internet lands.  I would suggest using google as it has little to do with SFML.

Solluxx

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Controlling Game Speed on Different Computers
« Reply #2 on: January 11, 2013, 07:13:54 am »
But doesn't SFML contain its own Time functions? alas your right I'll do some more research tomorrow.

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: Controlling Game Speed on Different Computers
« Reply #3 on: January 11, 2013, 07:52:57 am »
Here is a article that is referred to a lot when it comes to controlling game speed. Fix your timestep! You might have already seen it, but it's very interesting.
The sf::Time class just gives you an easy interface to time so it's not directly connected to your issue. But you can certainly use it to solve it.

Acrobat

  • Full Member
  • ***
  • Posts: 153
    • View Profile
Re: Controlling Game Speed on Different Computers
« Reply #4 on: January 11, 2013, 08:49:59 am »
sf::Clock

Solluxx

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Controlling Game Speed on Different Computers
« Reply #5 on: January 12, 2013, 05:19:55 am »
:/ damn that's all there is? But I want SFML to do it for me! lol ok tyvm

edit: I found this great article for controlling game speed and fps. Veterans and newbies alike should give it a read :)

http://www.koonsolo.com/news/dewitters-gameloop/
« Last Edit: January 12, 2013, 07:38:33 am by Solluxx »

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: Controlling Game Speed on Different Computers
« Reply #6 on: January 14, 2013, 05:27:42 am »
http://www.sfml-dev.org/documentation/2.0/classsf_1_1Window.php#af4322d315baf93405bf0d5087ad5e784

This function can make your life easier if you don't care about extreme precision, though it's always best to use a fixed time-step.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

Solluxx

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Controlling Game Speed on Different Computers
« Reply #7 on: January 14, 2013, 07:23:00 am »
I used a combination of the second last example in the article I linked and the setFrameratelimit to control the speed as well as cap it off so It only uses what processing power it really needs. It seems to be working pretty well.