Set FPS to ...?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Cocodrilo
Posts: 33
Joined: Fri Jul 21, 2006 9:27 pm
Location: Sweden, Eskilstuna
Contact:

Set FPS to ...?

Post by Cocodrilo »

Hello Everybody!
I just got a pretty simple question (prehaps).
How can i limit the framerate to 60 (or any other number)?

Thanks! :)
"Clicker"
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You have to enable vsync when creating the device.
Dances
Posts: 454
Joined: Sat Jul 02, 2005 1:45 am
Location: Canada
Contact:

Post by Dances »

If you can, you shouldn't limit your framerate. If you need to limit it to cap movement speeds, etc, then base them on time you'll be okay. Otherwise if VSync doesn't give you the results you want it'll be some really tedius coding... basically in your main loop you'll have to get the time, and see if .016 seconds have passed since your last frame; then decide to draw it based on that.
Cocodrilo
Posts: 33
Joined: Fri Jul 21, 2006 9:27 pm
Location: Sweden, Eskilstuna
Contact:

Post by Cocodrilo »

Welll.. im pretty bad at math, young and new at programming...
How do you mean, could u make a simple example. Dances please?
"Clicker"
Dances
Posts: 454
Joined: Sat Jul 02, 2005 1:45 am
Location: Canada
Contact:

Post by Dances »

Hmm okay if you want to use VSync then just set VSync to true when you create your device.

If you want to base your movement on time then at the end of every frame use getTime() and store it. Then when your character goes to move get the current time, do some math with the time you got, and came up with a movement distance. So if you do something like setPosition(vector3df(getPosition.X(), getPosition.Y(), currentTime - previousTime)) you'll end up with the node moving a distance equal to the milliseconds passed since the last frame was drawn.

If you want to limit your framerate to about 60 FPS get the time each time you draw your frame, and when you draw the next check if .016 of a second has passed, and only draw and grab the time if it has.
dejai
Posts: 522
Joined: Sat Apr 21, 2007 9:00 am

Post by dejai »

Lol people are usually trying to increase there Frame Rate Per Second not limit it.. :D
Programming Blog: http://www.uberwolf.com
kburkhart84
Posts: 277
Joined: Thu Dec 15, 2005 6:11 pm

Post by kburkhart84 »

dejai wrote:Lol people are usually trying to increase there Frame Rate Per Second not limit it.. :D
You know that is the truth!!

But yeah, you need to make your movement/physics based on actual time passed as explained above. You movement won't depend on the FPS, so like if your game skips a beat due to another program or whatever, the movement will "skip" but be where it is supposed to be according to the time passed.
Post Reply