What is the absolute fastest way to add 1 to a variable while retaining framerate independence?

0 favourites
  • 5 posts
From the Asset Store
Kids Game
$49 USD
New Sounds Added Update: 115 new sound effects added for no additional cost!
  • As the title says, what is the absolute fastest way to add 1 to a variable while retaining framerate independence?

    "Every tick" is fps dependent, "every 0.01 seconds" is not reliable, "n * dt" does not give the effect I'm looking for, and so on, so I'm not sure what to use.

  • I’d just add n*dt and int() the value every time you access it.

    I guess if you don’t need to access the variable very often you could just do this right before you access the value:

    Global number starttime=0

    Some condition

    — add (time-starttime)*dt to variable

    — set starttime to time

    — do something with the variable

    I doubt either would be noticeably faster.

  • Yeah I guess I'd have to, huh? Then just compare >= for any it skipped over for values greater than 1.

    I thought an expression that at 30 fps adds 2, or 120fps adds 0.5, and so on, would be more accurate..but fps is never perfectly stable, would result in floats, and is functionally similar to dt anyway so...blah.

  • I mean you could do an expression like:

    Set var to int(time*30)

    To get one to be added 30 times in a second. Then it would be just integers.

    In general the expression would be

    int((time-starttime)*rate)

    Do you want something to happen every time the car changes by one? I don’t think I follow why you’d need >=. I mean you could do something like the following to do something every time it changes by 1. Depending on what you want to happen you may have to do some interpolation if say you wanted to shoot bullets and they need to be spaced correctly.

    Global number prevVar=0

    Global number var=0

    Every tick

    — set prevVar to var

    — set var to int(time*30)

    Repeat var-prevVar times

    — do something

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I thought an expression that at 30 fps adds 2, or 120fps adds 0.5, and so on

    If you want to basically add 1 to a variable every tick, but take in to account framerate independence, then that's 60 * dt. It will do exactly what you said: every tick it will add 2 at 30 FPS, 1 at 60 FPS, 0.5 at 120 FPS, etc.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)