About Store Forum Documentation Contact



Post Reply 
Instructions per frame
Author Message
Dandruff Offline
Member

Post: #1
Instructions per frame
I noticed that instructions ran faster/slower depending on the fps. How can i make it so stuff is called once a second/few milliseconds instead of per frame?

Example: A button is clicked and the y of a window increases (like an animated drop down menu) - called per frame:
Code:
...gui_window->size().y+dropspeed...


The menu will either get bigger at the intended speed (based on the fps i got) or get bigger, slower (on lower fps). Any ideas?
04-14-2011 04:15 AM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #2
RE: Instructions per frame
Use Time.d(), not frames. For instance:

Code:
Flt time = 0;

void Update() {
    time += Time.d();
    
    if (time >= 1.0f) {
        // one second has occurred...
        time = 0;
    }
}
04-14-2011 04:53 AM
Find all posts by this user Quote this message in a reply
Dandruff Offline
Member

Post: #3
RE: Instructions per frame
Thanks! I tried it but i don't know how make use of that to make the speed of things go at the intended speed, but it will be useful for later. I came up with something like this:
Code:
Flt lagscale;
if(Time.d()>0.007) //0.007 is target frame time duration
lagscale=Time.d()-0.007;
...
speedofwhatever+=speedofwhatever*lagscale;
but i would have to do this for everything that needs to be scaled. Is there another way to do this? Like input.turn.x=Kb.b(KB_Q)-Kb.b(KB_E); - no matter how laggy the game is, it always turns at the same speed.
04-29-2011 04:27 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #4
RE: Instructions per frame
pos+=vel*Time.d();
04-29-2011 11:48 AM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #5
RE: Instructions per frame
(04-29-2011 04:27 AM)Dandruff Wrote:  Thanks! I tried it but i don't know how make use of that to make the speed of things go at the intended speed, but it will be useful for later.

Haha, yes, do what Esenthel posted. I thought you needed a timer by the way this question is worded: "How can i make it so stuff is called once a second/few milliseconds instead of per frame?"
04-29-2011 11:40 PM
Find all posts by this user Quote this message in a reply
Dandruff Offline
Member

Post: #6
RE: Instructions per frame
lol, yeah i don't know why i worded it that way either. Thanks for it though, im certain i would have made another topic sooner or later asking about making a timer smile

edit: works fine esenthel, thanks
(This post was last modified: 04-30-2011 04:28 AM by Dandruff.)
04-30-2011 12:30 AM
Find all posts by this user Quote this message in a reply
Post Reply