Delta Timer
Monkey Forums/Monkey Programming/Delta Timer
| ||
The delta timer in diddy that james wrote looks like this: [monkeycode] Class DeltaTimer Field targetfps:Float = 60 Field currentticks:Float Field lastticks:Float Field frametime:Float Field delta:Float Method New (fps:Float) targetfps = fps lastticks = Millisecs() End Method UpdateDelta:Void() currentticks = Millisecs() frametime = currentticks - lastticks delta = 'frametime / (1000.0 / targetfps) lastticks = currentticks End End [/monkeycode] However despite the name it does not seem to return the delta time, right? I noticed this when I attempted to use diddy's delta time and my game acted so wierd. I could not understand what it was until I found the delta time, from the delta class does not return a correct delta value. For example: Timer += dt.delta This will not increase the timer by 1 every second. This is how I expect a delta class to look like: [monkeycode] Class DeltaTimer Field LastTick:Int Field LastTickTime:Int Field Delta:Float Method New() lastticks = Millisecs() End Method UpdateDelta:Void() LastTickTime = Millisecs() -LastTick LastTick = Millisecs() Delta = LastTickTime * 0.001 End End [/monkeycode] However Monkey usually runs in a fixed framerate so using a fixed delta-time might be more sensible and accurate. Like this: [monkeycode] Class DeltaTimer Public Field Delta:Float Method New(fps:Float) Delta = 1.0 / fps End End [/monkeycode] I was curious to hear how you guys use delta and if I'm simply using the timer wrong then I'd like to ask how am I supposed to use it? |
| ||
Diddy appears to provide a delta in frame increments, not time. So you multiply whatever per frame movement value you have by the delta. There is no one way to use delta. In some games you don't want to use it at all. In many circumstances you might want to use delta timing to compensate for variable frame-rate but have an underlying limitation on how much variation from the desired interval you allow. |
| ||
Did not mean to sound like there was only one way, or that the diddy way is wrong, tough I realize it might have sounded like that. Diddy delta time use "frame time". I'm unfamiliar with this concept. I wounder how am I supposed to think when using it. Differences? Benefits? I know one benefit with the last version of delta is that the game can easily be replayed. If for example a replay-system is useful. Using all kinds of delta, even if not according to time has the benefit that one can use the delta to slow or speed up everything in the game. I usually only make use of delta time so I can write "200pixels/sec" instead of "speed 2.3 mystical units" - I never considered another type of delta time. One added benefit is that in multiplayer it is more likely that each platform plays at a similar speed. |
| ||
How can I use the delta timer in Diddy to speed up / slow down or even pause time? Or is there a better way? |
| ||
It depends on the game. You might want a way to increase or reduce the speed of the game, but there might be things you don't want to speed up. The simple way is to go into the source - add a variable to deltatime, let us call it gamespeed and multiply it with the deltatime variable. If gamespeed is 1, everything is as normal. If 0 everything will be "stuck". 0.5 = 50% speed, 2 = 200% speed, and so on. |