How can I limit the framerate?
by Ezra · in Torque Game Builder · 01/21/2006 (3:29 pm) · 4 replies
I'm noticing that the higher FPS my game runs at, the faster everything will move.. which really sucks.
Is there anyway to put a cap on the framerate, to lock it at 60, instead of allowing it to run at 500+ fps ? And then what about if the person's computer can only achieve 20fps max...
the way I'm moving my player and other objects is like this:
//these are depending on what keys are held down, resulting in 0, -1 or 1
%movex = $moveRight - $moveLeft;
%movey = $moveDown - $moveUp;
%vecdir = t2dVectorScale((%movex SPC %movey), 0.5);
%vec = t2dVectorAdd($player.getPosition(), %vecdir);
$player.setPosition( %vec );
Is there anyway to put a cap on the framerate, to lock it at 60, instead of allowing it to run at 500+ fps ? And then what about if the person's computer can only achieve 20fps max...
the way I'm moving my player and other objects is like this:
//these are depending on what keys are held down, resulting in 0, -1 or 1
%movex = $moveRight - $moveLeft;
%movey = $moveDown - $moveUp;
%vecdir = t2dVectorScale((%movex SPC %movey), 0.5);
%vec = t2dVectorAdd($player.getPosition(), %vecdir);
$player.setPosition( %vec );
About the author
Recent Threads
#2
-Michael
01/21/2006 (4:20 pm)
Try set $Pref::timeManagerProcessInterval to 2 (it is 0 by default). That may help.-Michael
#3
01/21/2006 (4:31 pm)
All of T2D's systems are built to be frame rate independent (i.e run the same speed, no matter the framerate). The reason this doesn't seem to be the case to you is because you are setting the position of your object yourself, instead of letting T2D handle it. Simply changing the last two lines to$player.setLinearVelocity(%vecdir);should solve the problem and provide you with the same results.
#4
%pos = t2dVectorAdd(%this.camera.getPosition(), %this.scrollDirection);
%this.camera.setPosition(%pos);
I think the same is done for the player as well in there.
01/21/2006 (4:53 pm)
Hmm ok, that explains it then! The reason I was using setPosition though is from the platformer tutorial, using their Auto Scroll function.. %pos = t2dVectorAdd(%this.camera.getPosition(), %this.scrollDirection);
%this.camera.setPosition(%pos);
I think the same is done for the player as well in there.
Torque Owner Ezra
equal to ( 60 / $fps::real ) ??
that way if the computer is going 581.3 FPS, I'd get some float .10321 etc.. and multiply the scale part of the vectors by that, and that would lower the increment when positioning players and enemies etc.. to properly match the intended speed at 60fps..
and then if the computer was going below 60 it would increase the speed to match what was intended at 60fps...
Is that going to completely screw up the physics system? or would I set the ScenePhysicsFPSActive to true, and set the Target to 60 (or whatever number I prefer to use for my 60 / $fps::real thing)
does that make any sense to anyone? I'm usually really bad at figuring out this kind of stuff.