File: GetDeltaTime.html

package info (click to toggle)
openlayer 2.1-2.1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 3,392 kB
  • ctags: 2,317
  • sloc: ansic: 10,433; cpp: 9,890; xml: 109; makefile: 90; sh: 36
file content (34 lines) | stat: -rw-r--r-- 5,246 bytes parent folder | download | duplicates (2)
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>&nbsp;playerX,&nbsp;playerY;
<br><font color="#777733">float</font>&nbsp;playerSpeedX,&nbsp;playerSpeedY;
<br><font color="#777733">float</font>&nbsp;playerAccelerationX,&nbsp;playerAccelerationY;
<br>
<br><font color="#999922">//&nbsp;The&nbsp;default&nbsp;fps&nbsp;is&nbsp;70.0&nbsp;//</font>
<br><a href="../FpsCounter.html"><font color="#0000CC">FpsCounter</font></a>::<a href="../FpsCounter/Start.html"><font color="#0000CC">Start</font></a>(&nbsp;<font color="#994400">70.0</font>&nbsp;);
<br>
<br><font color="#447711">while</font>(&nbsp;gameRunning&nbsp;)&nbsp;{
<br>&nbsp;&nbsp;<font color="#999922">//&nbsp;Tell&nbsp;OpenLayer&nbsp;that&nbsp;a&nbsp;new&nbsp;game&nbsp;frame&nbsp;has&nbsp;started.&nbsp;//</font>
<br>&nbsp;&nbsp;<a href="../FpsCounter.html"><font color="#0000CC">FpsCounter</font></a>::<a href="../FpsCounter/NewFrameStarted.html"><font color="#0000CC">NewFrameStarted</font></a>();
<br>&nbsp;&nbsp;
<br>&nbsp;&nbsp;<font color="#999922">//&nbsp;Get&nbsp;the&nbsp;delta&nbsp;time&nbsp;//</font>
<br>&nbsp;&nbsp;<font color="#777733">float</font>&nbsp;deltaTime&nbsp;=&nbsp;<a href="../FpsCounter.html"><font color="#0000CC">FpsCounter</font></a>::<a href="../FpsCounter/GetDeltaTime.html"><font color="#0000CC">GetDeltaTime</font></a>();
<br>&nbsp;&nbsp;
<br>&nbsp;&nbsp;<font color="#999922">//&nbsp;Change&nbsp;the&nbsp;speed&nbsp;of&nbsp;the&nbsp;player&nbsp;according&nbsp;to&nbsp;the&nbsp;acceleration&nbsp;//</font>
<br>&nbsp;&nbsp;playerSpeedX&nbsp;+=&nbsp;deltaTime&nbsp;*&nbsp;playerAccelerationX;
<br>&nbsp;&nbsp;playerSpeedY&nbsp;+=&nbsp;deltaTime&nbsp;*&nbsp;playerAccelerationY;
<br>&nbsp;&nbsp;
<br>&nbsp;&nbsp;<font color="#999922">//&nbsp;Move&nbsp;the&nbsp;player&nbsp;//</font>
<br>&nbsp;&nbsp;playerX&nbsp;+=&nbsp;deltaTime&nbsp;*&nbsp;playerSpeedX;
<br>&nbsp;&nbsp;playerY&nbsp;+=&nbsp;deltaTime&nbsp;*&nbsp;playerSpeedY;
<br>&nbsp;&nbsp;
<br>&nbsp;&nbsp;<font color="#999922">//&nbsp;Other&nbsp;game&nbsp;loop&nbsp;code&nbsp;//</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>