Skip to content

Commit

Permalink
docs(general):delta_time() example should not use hardcoded microseco…
Browse files Browse the repository at this point in the history
…nds value

YoYoGames/GameMaker-Bugs#8700

* Changed the code example to use game_get_speed(gamespeed_microseconds) and clarified that the base speed should also be expressed in pixels per step
* Small changes to game_get_speed() page
  • Loading branch information
YYBartT committed Dec 19, 2024
1 parent b883425 commit 716ce36
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>game_get_speed</title>
<meta name="generator" content="Adobe RoboHelp 2020" />
<meta name="generator" content="Adobe RoboHelp 2022" />
<link rel="stylesheet" href="../../../assets/css/default.css" type="text/css" />
<script src="../../../assets/scripts/main_script.js" type="module"></script>
<meta name="rh-authors" content="Mark Alexander" />
Expand All @@ -15,16 +15,16 @@
</head>
<body>
<!--<div class="body-scroll" style="top: 150px;">-->
<h1>game_get_speed</h1>
<p>This function can be used to get the game speed as either the number of game frames to run per second or as the number of micro seconds per game frame. Note that this is <b>not</b> the actual running speed FPS value (for that use the <a href="../Debugging/fps_real.htm"><span class="inline">fps_real</span></a> variable) but rather the number of game frames (FPS) that the game will attempt to maintain each second, or the length of each game frame in microseconds that the game will try to maintain (MPF). When you use this function you need to give one of the following constants which will determine the type of the return value:</p>
<h1><span data-field="title" data-format="default">game_get_speed</span></h1>
<p>This function can be used to get the game speed as either the number of game frames to run per second or as the number of microseconds per game frame. Note that this is <b>not</b> the actual running speed FPS value (for that use the <span class="inline2"><a data-xref="{title}" href="../Debugging/fps_real.htm">fps_real</a></span> variable) but rather the number of game frames (FPS) that the game will attempt to maintain each second, or the length of each game frame in microseconds that the game will try to maintain (MPF). When you use this function you need to give one of the following constants which will determine the type of the return value:</p>
<table>
<colgroup>
<col />
<col />
</colgroup>
<tbody>
<tr>
<th colspan="2"><span data-keyref="Type_Constant_GameSpeed"><a data-rhwidget="HyperlinkPopover" href="../../../../GameMaker_Language/GML_Reference/General_Game_Control/game_get_speed.htm">Game Speed Constant</a></span></th>
<th colspan="2"><span data-keyref="Type_Constant_GameSpeed"><a href="game_get_speed.htm" target="_blank">Game Speed Constant</a></span></th>
</tr>
<tr>
<th>Constant</th>
Expand All @@ -43,7 +43,7 @@ <h1>game_get_speed</h1>
<p>So, for example, if the game speed is set at 30 in the Game Options and you use the FPS type, then the function will return 30, but if you use the MPF then the function will return 33333.</p>
<p> </p>
<h4>Syntax:</h4>
<p class="code">game_get_speed(type);</p>
<p class="code"><span data-field="title" data-format="default">game_get_speed</span>(type);</p>
<table>
<tbody>
<tr>
Expand All @@ -53,32 +53,31 @@ <h4>Syntax:</h4>
</tr>
<tr>
<td>type</td>
<td><span data-keyref="Type_Constant_GameSpeed"><a data-rhwidget="HyperlinkPopover" href="../../../../GameMaker_Language/GML_Reference/General_Game_Control/game_get_speed.htm">Game Speed Constant</a></span></td>
<td><span data-keyref="Type_Constant_GameSpeed"><a href="game_get_speed.htm" target="_blank">Game Speed Constant</a></span></td>
<td>The type of method used to get the game speed (see the constants above).</td>
</tr>
</tbody>
</table>
<p> </p>
<h4>Returns:</h4>
<p class="code"><span data-keyref="Type_Real"><a data-rhwidget="HyperlinkPopover" href="../../../../LINKGOESHERE">Real</a></span></p>
<p class="code"><span data-keyref="Type_Real"><a href="../../GML_Overview/Data_Types.htm" target="_blank">Real</a></span></p>
<p> </p>
<h4>Example:</h4>
<p class="code">if (game_get_speed(gamespeed_fps) != 60) <br />
<p class="code">if (game_get_speed(gamespeed_fps) != 60)<br />
{<br />
    game_set_speed(60, gamespeed_fps);<br />
}</p>
<p>The above code checks to see if the game is running with a game speed of 60 FPS and if not it is set to 60 FPS.</p>
<p> </p>
<p> </p>
<p> </p>
<div class="footer">
<div class="buttons">
<div class="clear">
<div style="float:left">Back: <a href="General_Game_Control.htm">General Game Control</a></div>
<div style="float:right">Next: <a href="game_set_speed.htm">game_set_speed</a></div>
<div style="float:left">Back: <a data-xref="{title}" href="General_Game_Control.htm">General Game Control</a></div>
<div style="float:right">Next: <a data-xref="{title}" href="game_set_speed.htm">game_set_speed</a></div>
</div>
</div>
<h5><span data-keyref="Copyright Notice">© Copyright YoYo Games Ltd. 2022 All Rights Reserved</span></h5>
<h5><span data-keyref="Copyright Notice">© Copyright YoYo Games Ltd. 2024 All Rights Reserved</span></h5>
</div>
<!-- KEYWORDS
game_get_speed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,27 @@
</head>
<body>
<!--<div class="body-scroll" style="top: 150px;">-->
<h1>delta_time</h1>
<h1><span data-field="title" data-format="default">delta_time</span></h1>
<p>This variable returns the frame delta time, which is the time difference between the previous frame and the current frame. This value is in microseconds, where 1 microsecond is 1,000,000th of a second.</p>
<p>The purpose of delta timing is to eliminate the effects of the lag or slowness of computers that try to handle complex graphics or a lot of code. It is a value that can be multiplied with the speed of objects so that they will eventually move at the same speed, regardless of lag. This is achieved in <span data-keyref="GameMaker Name">GameMaker</span> by using the <span class="inline">delta_time</span> variable every step as it measures the time that has passed between one step and the next in microseconds. Therefore the variable <span class="inline">delta_time</span> can be used to calculate how much faster (for example) a game character has to move to make up for a lag spike in the game.</p>
<p>The purpose of delta timing is to eliminate the effects of the lag or slowness of computers that try to handle complex graphics or a lot of code. It is a value that can be multiplied with the speed of objects so that they will eventually move at the same speed, regardless of lag. This is achieved in <span data-keyref="GameMaker Name">GameMaker</span> by using the <span class="inline2"><span data-field="title" data-format="default">delta_time</span></span> variable every step as it measures the time that has passed between one step and the next in microseconds. Therefore the variable <span class="inline2"><span data-field="title" data-format="default">delta_time</span></span> can be used to calculate how much faster (for example) a game character has to move to make up for a lag spike in the game.</p>
<p> </p>
<h4>Syntax:</h4>
<p class="code">delta_time</p>
<p class="code"><span data-field="title" data-format="default">delta_time</span></p>
<p> </p>
<h4>Returns:</h4>
<p class="code"><span data-keyref="Type_Real"><a href="../../../GML_Overview/Data_Types.htm" target="_blank">Real</a></span> (integer)</p>
<p> </p>
<h4>Example:</h4>
<p class="code">var _dt = delta_time / 1000000;<br />
<p class="code">var _dt = <span data-field="title" data-format="default">delta_time</span> / game_get_speed(gamespeed_microseconds);<br />
speed = spd * _dt;</p>
<p>The above code will set the speed of the instance using delta-time to correct for lag. The variable &quot;_dt&quot; would be used to hold the previously calculated delta time value so that the ratio can be used to multiply the base speed value (held in the variable &quot;spd&quot;) and to get a consistent speed for the instance.</p>
<p> </p>
<p>The above code will set the <span class="inline2"><a data-xref="{title}" href="../../Asset_Management/Instances/Instance_Variables/speed.htm">speed</a></span> of the instance taking delta time into account to correct for lag. The variable <span class="inline2">_dt</span> would be used to hold the previously calculated delta time value so that the ratio can be used to multiply the base speed value (held in the variable <span class="inline2">spd</span> and expressed in the same units as <span class="inline2">speed</span>, i.e. pixels per step) and to get a consistent speed for the instance.</p>
<p> </p>
<p> </p>
<div class="footer">
<div class="buttons">
<div class="clear">
<div style="float:left">Back: <a href="Date_And_Time.htm">Date And Time</a></div>
<div style="float:right">Next: <a href="date_set_timezone.htm">date_set_timezone</a></div>
<div style="float:left">Back: <a data-xref="{title}" href="Date_And_Time.htm">Date And Time</a></div>
<div style="float:right">Next: <a data-xref="{title}" href="date_set_timezone.htm">date_set_timezone</a></div>
</div>
</div>
<h5><span data-keyref="Copyright Notice">© Copyright YoYo Games Ltd. 2024 All Rights Reserved</span></h5>
Expand Down

0 comments on commit 716ce36

Please sign in to comment.