TimeDelta

For questions about using Classic.

Post » Tue May 12, 2009 10:34 am

You don't need to change your monitor's refresh rate to test different framerates - change the framerate to 'Fixed' at 10fps in application properties, or set it uo 'unlimited' (which should reach a few hundred frames per second at least), and the difference will become obvious.

The problem is framerate dependent code (like set X to .X + 1) doesn't have a fixed speed (it depends on the framerate), and TimeDelta code does have a fixed speed. So how can you possibly convert between them? TimeDelta always means one speed, and without TimeDelta it could be any speed, depending on your framerate. So to convert to or from framerate-dependent, you have to pick a framerate as your reference, and 60fps is a common one so a good choice.

My advice, though, is to completely ditch framerate-dependent code. Forget it. Just always use TimeDelta, and get everything moving at the right speed using that. Don't bother converting between them, it's totally unecessary if you start making your game right off the bat with TimeDelta. Also, don't forget the built in behaviors are already framerate-independent, so you don't need to worry about them.

I hope that's clear, it can be a tricky area to explain! By the way, you should avoid the 'Every X ticks' event in games, because as the name suggests, it runs depending on the framerate (every 10 ticks is once a second at 10fps, but ten times a second at 100fps!). You always want to use 'real world' times, so use 'every X milliseconds'. TimeDelta is another way of using real world times, so with the two, your game should run at the same speed everywhere! :)
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Tue May 12, 2009 11:22 am

What Ashley said is a perfect explanation. However, if your game requires pixel perfect collisions, and you don't want to risk an object "skipping through" parts of your level because the frame rate dropped too much, then that's when you should use a fixed frame rate. Time delta also has an option to prevent skipping like that from happening by slowing down the game if it drops below a certain frame rate. But if you're doing a low res game, i'd say use fixed rate. The tearing is barely noticeable, and it evens adds that old console nostalgia look.

[u:rze1hhsb]MAJOR DIFFERENCE BETWEEN FIXED RATE AND TIMEDELTA[/u:rze1hhsb]
Timedelta- makes your game have skip lag.
Fixed rate- makes your game have slowdown lag.
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

Post » Tue May 12, 2009 12:19 pm

I'd disagree and say you should never publish a game with fixed framerate mode, but people can and do ignore me on that one ;)
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Tue May 12, 2009 7:34 pm

I have played around with the different settings, and using the fixed frame rate really slugs the game, it's gets jerky and awkward feeling.

Ashley, Thanks for that tip about adjusting the frame rate, obvious now, but I do usually tend towards doing things the long awkward difficult and barely functional ways.

Now I don't mind showing graphics off...but when it comes to code, I'm so terrible at it i prefer to hide it away. But if you guys could give me an idea as to how to sort this out into the TimeDelta light?



2 ticks would work out to 0.03 milliseconds, and 5 to 0.08, but because the time, is system based, I would need to add TimeDelta to the milliseconds? Is that correct? And i want 0.03 to be a derivative of 60?
B
9
S
2
G
4
Posts: 346
Reputation: 2,726

Post » Tue May 12, 2009 7:47 pm

Aha! I think I understand why you're confused. Forget the conditions - you use timedelta in the actions only.

So instead of what you're doing:

every 2 ticks
left arrow is down
- subtract 1 from camera x

do this:

left arrow is down
- subtract (amount per second*timedelta) from camera x

Since you're using every two ticks, the event is running every other frame, resulting in 30 pixels moved per second. To get a speed equal to that, you'd use (30*timedelta). Like this:

left arrow is down
- subtract (30*timedelta) from camera x
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Tue May 12, 2009 9:10 pm

That's right, since TimeDelta is the time since the last tick, you want to use it in events that run every tick.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Tue May 12, 2009 11:56 pm

So do built in behaviors like Platform/8 Direction/etc take this into account when moving objects?
B
2
G
3
Posts: 15
Reputation: 880

Post » Tue May 12, 2009 11:58 pm

Yes, all the built in behaviors use TimeDelta.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Fri May 15, 2009 6:16 am

[quote="Davioware":9c2cf11s]However, if your game requires pixel perfect collisions, and you don't want to risk an object "skipping through" parts of your level because the frame rate dropped too much, then that's when you should use a fixed frame rate.[/quote:9c2cf11s]

Actually you just have to set bounds on your game world

Say your thinnest object is 10px wide on it's smallest side (careful with convex objects). Then you can't have *any* object move 20px or more on a single tick, else you risk skipping it. Then you gotta cap it. Say your fastest object goes at 100px per second (100*Timedelta).

We'll set a safety margin of 15%
20px * (1- 0.15) = 20px*0.85 = 17px
100[px/s] / 17[px] = 5.8[1/s]

thus 5.8 is the minimum FPS, which can be set directly in Construct.

Test: at 5.8FPS (5.8[1/s]) an object going at 100[px/s] will advance 100/5.8 [px] = 17.24, which is less than our thinnest object (20px), thus collision would be detected.
:D

With unaligned bounding boxes or pixel-perfect collision however things change, as a tiny corner of a big object could mean a collision. In that case you just gotta decide (in numbers) how forgiving the game is.

(this took quite a while to piece together, did a long time ago)
Edit: some math and spelling goofs :mrgreen:
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Previous

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests