1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transistional//EN"><html><head><title>OpenLayer Offline Manual</title><style type="text/css" media="all">@import "../CrystalStyle.css";</style><body bgcolor="FFFFFF" ><div align="center" style="pagestyle"><table width="60%"><tr><td><div class="parentLinks"><a href="../index.html">OpenLayer</a> | <a href="../FpsCounter.html">FpsCounter</a> | <a href="../FpsCounter/GetDeltaTime.html">GetDeltaTime</a></div><br><div class="BigHeader">GetDeltaTime</div><br><div class=""><div class="Surrounded"><table><tr valign="top"><td align="right"><div class="FuncDef"><strong><font color="#777733">static</font> <font color="#777733">float</font> <a href="../FpsCounter/GetDeltaTime.html"><font color="#0000CC">GetDeltaTime</font></a>();
<br></strong></div></td></tr></table>
<br>Get the elapsed game time between this and the previous frame.
<br></div>
<br>The speed regulation requires you to multiply all speed and position and rotational changes with the delta time.
<br>
<br>Using this function requires to start the fps counter before the game loop starts and to call <a href="../FpsCounter.html"><font color="#0000CC">FpsCounter</font></a>::<a href="../FpsCounter/NewFrameStarted.html"><font color="#0000CC">NewFrameStarted</font></a>() in the beginning of each frame.
<br>
<br>Note that the fps counter has to be started before calling this function.</div><br><div class="MediumHeader">Examples</div><br><div class="Code"><font color="#777733">float</font> playerX, playerY;
<br><font color="#777733">float</font> playerSpeedX, playerSpeedY;
<br><font color="#777733">float</font> playerAccelerationX, playerAccelerationY;
<br>
<br><font color="#999922">// The default fps is 70.0 //</font>
<br><a href="../FpsCounter.html"><font color="#0000CC">FpsCounter</font></a>::<a href="../FpsCounter/Start.html"><font color="#0000CC">Start</font></a>( <font color="#994400">70.0</font> );
<br>
<br><font color="#447711">while</font>( gameRunning ) {
<br> <font color="#999922">// Tell OpenLayer that a new game frame has started. //</font>
<br> <a href="../FpsCounter.html"><font color="#0000CC">FpsCounter</font></a>::<a href="../FpsCounter/NewFrameStarted.html"><font color="#0000CC">NewFrameStarted</font></a>();
<br>
<br> <font color="#999922">// Get the delta time //</font>
<br> <font color="#777733">float</font> deltaTime = <a href="../FpsCounter.html"><font color="#0000CC">FpsCounter</font></a>::<a href="../FpsCounter/GetDeltaTime.html"><font color="#0000CC">GetDeltaTime</font></a>();
<br>
<br> <font color="#999922">// Change the speed of the player according to the acceleration //</font>
<br> playerSpeedX += deltaTime * playerAccelerationX;
<br> playerSpeedY += deltaTime * playerAccelerationY;
<br>
<br> <font color="#999922">// Move the player //</font>
<br> playerX += deltaTime * playerSpeedX;
<br> playerY += deltaTime * playerSpeedY;
<br>
<br> <font color="#999922">// Other game loop code //</font>
<br>}</div><div class=""><br><br><div class="MediumHeader">Other functions of the class <a href="../FpsCounter.html"><font color="#0000CC">FpsCounter</font></a></div><div class="Surrounded"><table size="100%" cellpadding="0" cellspacing="0"><tr><td halign="center" class="funclist"><a href="../FpsCounter/Start.html">Start</a></td><td width="65%" halign="center"><div class="smalltext">Starts the FPS counter</div></td></tr><tr><td halign="center" class="funclist"><a href="../FpsCounter/NewFrameStarted.html">NewFrameStarted</a></td><td width="65%" halign="center"><div class="smalltext">Tells OpenLayer that a new game frame has started</div></td></tr><tr><td halign="center" class="funclist"><a href="../FpsCounter/GetDeltaTime.html">GetDeltaTime</a></td><td width="65%" halign="center"><div class="smalltext">
Get the elapsed game time between this and the previous frame</div></td></tr><tr><td halign="center" class="funclist"><a href="../FpsCounter/GetFps.html">GetFps</a></td><td width="65%" halign="center"><div class="smalltext">
Returns the frames per second the program runs at</div></td></tr><tr><td halign="center" class="funclist"><a href="../FpsCounter/Pause.html">Pause</a></td><td width="65%" halign="center"><div class="smalltext">Pauses the FPS counter</div></td></tr><tr><td halign="center" class="funclist"><a href="../FpsCounter/Resume.html">Resume</a></td><td width="65%" halign="center"><div class="smalltext">Resumes the paused FPS counter</div></td></tr></table></div><br><div class=""><a href="../index.html">Back to the main page of the manual</a></div><br>Questions about GetDeltaTime? Click <a href="http://crystalstorm.ath.cx/index.php?lan=en&page=CreateFeedback&subject=GetDeltaTime">here.</a></div></td></tr></table></body></html>
|