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 / Timings in a game

Author
Message
Mike Archer
9
Years of Service
User Offline
Joined: 19th Feb 2015
Location: Wales
Posted: 2nd Dec 2015 00:57
I may be missing something, but is there any way to create a reliable way to make a game run at a set speed for a prolonged period of time? Basing it on FPS means it will run slower on some machines, but using the timer means it will become inaccurate after a couple of hours due to the timer being floating point. Is there any way to reset the timer back to zero to keep accuracy, or should I rely on FPS?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 2nd Dec 2015 09:09
You may kick yourself...

ResetTimer()
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Preben
AGK Studio Developer
20
Years of Service
User Offline
Joined: 30th Jun 2004
Location:
Posted: 2nd Dec 2015 12:10
You can do something like this:

the first lines in your sync loop:
fps#=1/GetFrameTime()
tween#=60/fps#

Then anytime you like to move something you just do like this:

cammove#=-GetVirtualJoystickY( 1 ) * tween#

or moving a object:

SetObjectPosition(door1[a],GetObjectX(door[a]),GetObjectY(door[a])-(1.0*tween#),GetObjectZ(door1[a]))

here 1.0 is the speed you like it to move at ( when you make the * tween# it will add to this is the fps is low , so you move at the same speed no matter the FPS ).

SetObjectRotation(gunobj, GetObjectAngleX(gunobj), GetObjectAngleY(gunobj)+(0.1*tween#), GetObjectAngleZ(gunobj) )

Here i like to move 0.1 each cycle so use 0.1*tween#


best regards Preben Eriksen,
Mike Archer
9
Years of Service
User Offline
Joined: 19th Feb 2015
Location: Wales
Posted: 2nd Dec 2015 14:36
Thank you, I couldn't understand why there was no option to reset the timer, and now I can't understand how I didn't see it... lol
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 2nd Dec 2015 17:31
GetFrameTime() is useful... allows you to end up dealing in "pixels per second" type movement which is ultimately what you need.
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)

Login to post a reply

Server time is: 2024-11-21 14:57:21
Your offset time is: 2024-11-21 14:57:21