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.

Newcomers AppGameKit Corner / Delta Timing - FixedRateLogic - Is there a built in solution?

Author
Message
Amon
6
Years of Service
User Offline
Joined: 30th May 2014
Location: Shropshire, United Kingdom
Posted: 27th Mar 2018 03:35
Delta Timing - FixedRateLogic - Is there a built-in solution, or should I roll my own if I can?

What do you guys use to make sure things run at the same speed on different hardware?
Imaginations' greatest gift is the knowledge you supply it.
Amon
6
Years of Service
User Offline
Joined: 30th May 2014
Location: Shropshire, United Kingdom
Posted: 27th Mar 2018 03:44


Found this. Wondered if anyone more proficient in agk2 can convert it?
Imaginations' greatest gift is the knowledge you supply it.
Bengismo
2
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 27th Mar 2018 08:49 Edited at: 27th Mar 2018 08:52
https://www.appgamekit.com/documentation/examples/timers/1_timer_movement.htm

Its fairly well covered in the documentation. ^^^

The easiest way is to just use GetFrameTime() but if you want total accuracy then Sampling the Timer() value each frame and calculating the difference is a good choice.

Its also been covered on the forum quite a few times too:
https://forum.thegamecreators.com/thread/212840
Amon
6
Years of Service
User Offline
Joined: 30th May 2014
Location: Shropshire, United Kingdom
Posted: 30th Mar 2018 02:51
I have yet to find or code anything working. Hmm. I'll keep battling away. Thanks though.
Imaginations' greatest gift is the knowledge you supply it.
Bengismo
2
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 30th Mar 2018 10:35
For fixed rate logic....you simply add GetFrameTime() to a Total each frame and then do a while loop for each fixed rate time step you want to take.

inc Total#, GetFrameTime() // alternatively use a DeltaTime# calculated from previous and current Timer() values

while Total#>FixedTimeStep#

Do 'fixed rate' logic here...

dec Total#, FixedTimeStep#
loop

So, no matter what your FPS or sync rate, the fixed rate logic gets called the same amount every second. Just remember to pass FixedTimeStep# to any time based functions.
Amon
6
Years of Service
User Offline
Joined: 30th May 2014
Location: Shropshire, United Kingdom
Posted: 30th Mar 2018 13:44
Thank you. If you could help us with a working bit of code so I can just plug n play I would greatly appreciate it. No worries if not though as I appreciate your help.
Imaginations' greatest gift is the knowledge you supply it.
Amon
6
Years of Service
User Offline
Joined: 30th May 2014
Location: Shropshire, United Kingdom
Posted: 30th Mar 2018 16:46 Edited at: 30th Mar 2018 16:47
This is a snippet of my code. When I try to multiply the characters movement by 'difference' the character does not move, at all.

Imaginations' greatest gift is the knowledge you supply it.
Bengismo
2
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 30th Mar 2018 17:02 Edited at: 30th Mar 2018 17:03
difference is not the same variable as difference#

So your difference variable just sits at 0 and never changes - remove the #


The guide posted in my first reply covers this in detail and has working code....

Login to post a reply

Server time is: 2020-10-27 17:59:42
Your offset time is: 2020-10-27 17:59:42