How do I make this code framerate independent?

0 favourites
  • 2 posts
From the Asset Store
5 levels with simple coding Source-code (.c3p) + HTML5 Exported
  • Okay, before you click off, I know what delta time is.

    I've read through the manual, and some examples, but I'm not exactly sure how to apply it here. I've tried several ways, none worked.

    My development environment's refresh rate was 240, this PC has 60.

    Here's the ORIGINAL code I'm trying to revamp:

    I am well aware delta time only works if the condition is Every Tick. I've tried several ways, including +/- ((value)*dt*240) and +/- (value * (0.41666666666/dt)). Those didn't work.

    Any practical ideas are welcome. Thanks.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So as you have it now the “every 0.01 seconds” it would trigger ~100 times a second on a 240fps screen, and 60 times a second on a 60fps screen ( since anything lower than dt is dt with every x seconds.

    If you want it to update at the same fixed rate you could remove the every 0.01 seconds and do something like this.

    Var t=0
    
    Every tick
    — set t to t%1
    — add 100*dt to t
    
    Repeat int(t) times
    — do stuff

    Or did you want it to be continuous instead of doing the steps you were using?

    For that, remove the every 0.01 seconds and change the set x’s from:

    Set x to self.x+rate

    to

    Set x to self.x+rate*100*dt

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