Timer is affected by framerate?

For questions about using Classic.

Post » Mon Oct 03, 2011 11:41 am

I'm using "Timer%7=1" in a condition, to do something every X miliseconds (I can't use the actual "every x miliseconds" event since for some reason it stuffs up the picking).

However, on unlimited framerate the event is trigged a billion times faster? I thought the timer wouldn't be affected by framerate like how timedelta isn't?
B
134
S
65
G
16
Posts: 1,765
Reputation: 19,188

Post » Mon Oct 03, 2011 12:31 pm

There were lots of threads and discussions about this. May search for them if you want to read more about it. It is the simple fact that nothing gets triggered faster than a frame. If a game runs with 60 fps, then the shortest timespan that can be distinguished is 1/60 (ca 16.67 ms)
So your event is triggered every 16.67ms and only if at that time the timer modulo divided by 7 is 1 the event will actually be executed:
frame 1 timer = 0 | timer%7 = 0
frame 2 timer = 16 | timer%7 = 2
frame 3 timer = 33 | timer%7 = 5
frame 4 timer = 50 | timer%7 = 1 <-first executed event

Of course, the hits will raise if in unlimited framerate, because with something like 1000 fps the shortest timespan is 1/1000 = 1 ms, and therefore timer%7 will match 1 much more often.

Just don't use timespans shorter than the framerate and use a range rather than a definite value (e.g. see it valid if timer%x is lower than 5 or something)
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Tue Oct 04, 2011 12:04 am

Thanks I think I understand it better now.
B
134
S
65
G
16
Posts: 1,765
Reputation: 19,188


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests