Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / timer-based movement

Author
Message
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 20th Feb 2013 00:48
User clicks on two adjacent boxes to swap them, and using a little timer-based animation, they move into each other's places. The only thing affected by the timer is the positions of the two boxes, the drawing is independent.

Seemed simple enough to me, but the movement is slower when I cap the frame rate at 60 versus leaving it unlimited (which is around 6600fps for me).

My only thought is that by running at a higher frame rate, the timer check happens more frequently and thus stays more accurate to the 10ms delay I set.




"You're all wrong. You're all idiots." ~Fluffy Rabbit
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 20th Feb 2013 03:26 Edited at: 20th Feb 2013 03:29
Well this is not timer based movement seeing as the speed it moves is not based on frame ticks.

Your thoughts are correct, this line [inc t#, 0.04] would be check quicker at a high frame rate so it would reach it's target quicker.

Timer based movement works by calculated the difference of the timer between frames (delta), using this we can accurate update things at a consistent speed whatever the frame rate (sort of, starts to get more complicated depending on what sort of TMB you want, then you have to deal with timer overflow and bla bla bla... google is your friend). The simple version, I've edited your code (look for the Sasuke tags):

Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 20th Feb 2013 04:04
I added my super-secret-special toggle code and now we have optional click and drag!


I don't have a2d, well I do because I just downloaded it but I don't know how to "install" it. (Can dbp free version use plugins?)

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 20th Feb 2013 16:51
I would think, regardless of framerates, my example would update every 10ms.

Thanks.


Quote: "Can dbp free version use plugins?"

Only difference between free and not free is the ad in the IDE.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 20th Feb 2013 17:10 Edited at: 20th Feb 2013 17:14
If you've capped the frame rate at 60 frames per second, then each frame takes 16.6 milliseconds. So your check will always return true that the amount of time since the last frame is greater than or equal to 10 milliseconds but will still only be running every 16.6 milliseconds. Also, if you removed the cap and your rendering happened to take up 9 milliseconds then the first time it checked whether or not to update it would fail and the next time it would succeed but would've waited 18 milliseconds to have done so. Proper timer based movement would avoid both of these issues.

[Edit] Fixing stupid punctuation mistake. [/Edit]


Previously TEH_CODERER.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 20th Feb 2013 17:23 Edited at: 20th Feb 2013 17:25
Quote: "I would think, regardless of framerates, my example would update every 10ms."


It's because this line if timestamp+10 <= timer() is called far more often at a higher frame rate. So the statement will be considered true before a lower frame rate finds that it's true.

Andrew beat me to it
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 20th Feb 2013 17:32
The way I approached it in my game is with the following:



The function updateTimeCriticalStuff() is guaranteed to be called 60 times a second, no matter what.

TheComet

http://blankflankstudios.tumblr.com/
"You're all wrong. You're all idiots." - Fluffy Rabbit
"Bottom line, people are retarded." - Fluffy Rabbit
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Feb 2013 00:37
Thanks guys.

Comet, nice signature

"You're all wrong. You're all idiots." ~Fluffy Rabbit
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 21st Feb 2013 07:25
Likewise.

TheComet

http://blankflankstudios.tumblr.com/
"You're all wrong. You're all idiots." - Fluffy Rabbit
"Bottom line, people are retarded." - Fluffy Rabbit

Login to post a reply

Server time is: 2026-07-07 18:44:31
Your offset time is: 2026-07-07 18:44:31