Timedelta question

This forum is currently in read-only mode.
From the Asset Store
Logo Quiz with 150 prepared logos and answers, automatic question and answer mixing
  • I'm still trying to understand where to apply timedelta. Instead of having to apply it to so many things, can I just have an event which is "every millesecond" then have tons of events under that event as sub-events? Since the every [time] conditions are affected by timescale, can't I just put everything under an event like that?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm not quite sure what you mean.

    The time scale is just one project-wide setting, you can't apply it to a few things but not to others. When you set the time scale to 0.5, everything moves half as fast.

  • I think he means timedelta. What he's proposing (I think), is instead of using timedelta in expressions, of putting the whole game in a every x milliseconds event. That could work in theory.. but then if you have a really fast framerate, the game will be stationary for many frames, instead of moving in smaller, incremental steps. You should do some experimenting to see how reliable the solution is, and how it affects smoothness of the game. However, if you do this, then change the timescale, the game framerate will just slow down. instead of smoothly slowing down while keeping framerate.

  • ...can I just have an event which is "every millesecond" then have tons of events under that event as sub-events?

    No, you can't!

    I can't stress this statement enough. 'every x millisecond' is not a reliable way of programming time based! Its timeslice is dependent on the framerate and that is exactly what you try to avoid when using a delta time.

    If your game runs at 60 fps, the shortest timeslice you get for 'every' is 1/60s, ~17ms. You could try to set the condition to 17ms, but if for whatever reason the game runs on another computer with 30 fps the shortest timeslice is 1/30 or ~34 ms. In result, the game will be half as fast as on the first computer, because the 'every'-event is still triggered on every tick...

    Btw, the example above also shows, that you can't even set the actual values but an approximation (e.g. 17 instead of 16.666666666666...)

    This is actually an interesting problem because the Every event can only trigger at most once per tick (like Always). So if you're running at 10fps, the Every event will only trigger at most every 100ms. This is kind of awkward because it can make things framerate dependent again, even in well-designed, framerate-independent games.

    h2]Source

    'Every x milliseconds' also triggers in the next possible tick, not at the exact time. For example, with 60 fps, the 20th tick is reached at 333.33333333...ms, the 19th at 316.6666666...ms. If you'd now have it run 'every 320 milliseconds' it will occur in the 20th tick, not in between tick 19 and 20. This isn't that bad when just, let's say, switching a light on and off, but it is crucial when constantly moving a sprite or fading a color, etc. It will get slowly out of time.

    Here is a cap. Run it and watch for a while (half a minute or more). The two sprites are both set to repeatedly move 400 pixels per second. The one above uses timedelta, the one below uses 'every...' I think, seeing this is better than a thousand words.

    TimeDeltaVSeveryXms.cap

  • Thanks so much.

  • Good explanation, tulamide. Note Construct 2 uses seconds as its default unit of time, instead of milliseconds like 0.x. I think too many people assume since they type in a quantity of milliseconds it is accurate to the millisecond. It's only accurate to a tick, though, so I guess it is a little misleading... a good article on ticks and timing would be useful...

  • So is it ok to do something Every 1 second? Or is it only bad to use small millisecond events?

  • It's not bad to use millisecond events. It only gets inaccurate if you're using a very small number of milliseconds, because your timed event might fall between ticks and won't get passed until the next tick.

    90% of the time it's such a tiny discrepancy that it won't visibly affect your game at all. But as a general rule I usually don't use anything less than about 50 milliseconds, unless you know without a doubt that it's not going to be an issue.

    Edit:

    For things like smooth motion and fading sprites and such, as tulamide was saying, it's a good idea to use timeDelta, yes. For things like machine guns spawning bullets, using Every X millisecond is fine, and if you have a small number of milliseconds then it's not going to affect your game too much.

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