Just for others, I incorporated managing delta time into separate functions. Just for this example I took the timer movement example included with the install and modified it. Not saying it has to be done this way but I thought it would work pretty well and encapsulate the functionality as much as possible. This is my first attempt posting code to the forum so hopefully I did it correctly
main.agc
#option_explicit
#include "TimeManagement.agc"
// use of timers
// set a virtual resolution
SetVirtualResolution ( 320, 480 )
// vsync state
fullspeed as integer = 1
TimeManagement as TimeManagementDef
x as float
// display a background
CreateSprite ( LoadImage ( "background7.jpg" ) )
// load an image and create a sprite
LoadImage ( 1, "blue.png" )
CreateSprite ( 1, 1 )
SetSpritePosition ( 1, 0, 200 )
// set 60 fps in CPU friendly mode
SetSyncRate( 60, 0 )
TimeManagement = TimeManagementInitialize()
// main loop
do
TimeMangementProcess(TimeManagement)
// move the sprite and take into account the frame time
// the box will move at 20 units per second
// i.e. if the last frame took 0.1 seconds to render the box would
// be moved 2 units, if the frame took 1 second the box would
// move 20 units to catch up to where it should be
x = GetSpriteX ( 1 )
x = x + 20.0 * TimeManagement.difference
SetSpriteX ( 1, x )
// display instructions and information
Print ( "Touch or click the screen to switch" )
Print ( "between 60fps and 20fps" )
Print ( "The box should move at the same speed" )
Print ( "regardless of frame rate" )
Print ( "" )
if ( fullspeed = 1 ) then Print ( "Target Speed = 60fps" ) else Print ( "Target Speed = 20fps" )
Print ( "Frame rate = " + str ( screenFPS ( ) ) )
// change vsync on input
if GetPointerPressed ( ) = 1
if fullspeed = 1
SetSyncRate(20,0)
fullspeed = 0
else
SetSyncRate(60,0)
fullspeed = 1
endif
endif
// update the screen
Sync ( )
loop
TimeManagement.agc
#option_explicit
type TimeManagementDef
thisFrame as float
lastFrame as float
difference as float
endtype
function TimeManagementInitialize()
TimeManagement as TimeManagementDef
TimeManagement.lastFrame = Timer()
TimeMangementProcess(TimeManagement)
endfunction TimeManagement
function TimeMangementProcess(TimeManagement ref as TimeManagementDef)
TimeManagement.thisFrame = Timer()
TimeManagement.difference = TimeManagement.thisFrame - TimeManagement.lastFrame
TimeManagement.lastFrame = TimeManagement.thisFrame
endfunction