<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://wiki.spheredev.org/index.php?action=history&amp;feed=atom&amp;title=API%3ASphere.now</id>
		<title>API:Sphere.now - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://wiki.spheredev.org/index.php?action=history&amp;feed=atom&amp;title=API%3ASphere.now"/>
		<link rel="alternate" type="text/html" href="http://wiki.spheredev.org/index.php?title=API:Sphere.now&amp;action=history"/>
		<updated>2026-05-10T13:39:12Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.29.0</generator>

	<entry>
		<id>http://wiki.spheredev.org/index.php?title=API:Sphere.now&amp;diff=10158&amp;oldid=prev</id>
		<title>Bruce Pascoe: Clarify some stuff, add note on odometer rollover</title>
		<link rel="alternate" type="text/html" href="http://wiki.spheredev.org/index.php?title=API:Sphere.now&amp;diff=10158&amp;oldid=prev"/>
				<updated>2017-11-15T05:55:45Z</updated>
		
		<summary type="html">&lt;p&gt;Clarify some stuff, add note on odometer rollover&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 05:55, 15 November 2017&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l13&quot; &gt;Line 13:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 13:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== Description ===&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== Description ===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;'''&amp;lt;tt&amp;gt;Sphere.now()&amp;lt;/tt&amp;gt;''' returns the number of complete &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;frames processed &lt;/del&gt;since the calling game started.&amp;#160; Therefore, on the very first frame this will return 0, on the next frame 1, and so on.&amp;#160; &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Specifically the return value is the number of full event loop turns, which by definition is the same as the number of updates performed.&amp;#160; This allows you to use &lt;/del&gt;&amp;lt;tt&amp;gt;Sphere.now()&amp;lt;/tt&amp;gt; as a frame-perfect timer &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;in cases where using &lt;/del&gt;wall-clock time &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;(e.g. &amp;lt;tt&amp;gt;Date.now()&amp;lt;/tt&amp;gt;) is not desirable&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;'''&amp;lt;tt&amp;gt;Sphere.now()&amp;lt;/tt&amp;gt;''' returns the number of complete &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;event loop turns &lt;/ins&gt;since the calling game started&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;, each event loop turn corresponding to a frame&lt;/ins&gt;.&amp;#160; Therefore, on the very first frame this will return 0, on the next frame 1, and so on.&amp;#160; &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Because &lt;/ins&gt;&amp;lt;tt&amp;gt;Sphere.now()&amp;lt;/tt&amp;gt; &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;counts frames instead of wall-clock time, this allows you to use it &lt;/ins&gt;as a frame-perfect timer&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;, which is often more predictable than &lt;/ins&gt;wall-clock time&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;, particularly if the game begins dropping frames&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;By default, Sphere &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;will regulate updates so &lt;/del&gt;that 60 frames &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;will be &lt;/del&gt;processed every second (60 FPS).&amp;#160; Your game can change that by setting the value of &amp;lt;tt&amp;gt;[[API:Sphere.frameRate|Sphere.frameRate]]&amp;lt;/tt&amp;gt; to something other than 60.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;By default, Sphere &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;regulates the event loop such &lt;/ins&gt;that 60 frames &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;are &lt;/ins&gt;processed every second (60 FPS).&amp;#160; Your game can change that by setting the value of &amp;lt;tt&amp;gt;[[API:Sphere.frameRate|Sphere.frameRate]]&amp;lt;/tt&amp;gt; to something other than 60.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== Parameters ===&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== Parameters ===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l23&quot; &gt;Line 23:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 23:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== Return Value ===&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== Return Value ===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The number of complete frames processed since the game started running.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The number of complete frames processed since the game started running&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;.&amp;#160; This value will roll over, like an odometer, after exactly 4,294,967,296 frames.&amp;#160; This is not a practical concern: running at 60 frames per second, your game would need to run continuously, ''for 2 years straight'', before the counter will roll over&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== See Also ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== See Also ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Bruce Pascoe</name></author>	</entry>

	<entry>
		<id>http://wiki.spheredev.org/index.php?title=API:Sphere.now&amp;diff=10157&amp;oldid=prev</id>
		<title>Bruce Pascoe: Add Sphere.now() page</title>
		<link rel="alternate" type="text/html" href="http://wiki.spheredev.org/index.php?title=API:Sphere.now&amp;diff=10157&amp;oldid=prev"/>
				<updated>2017-11-02T16:32:51Z</updated>
		
		<summary type="html">&lt;p&gt;Add Sphere.now() page&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{DISPLAYTITLE:Sphere.now()}}&lt;br /&gt;
&lt;br /&gt;
The '''&amp;lt;tt&amp;gt;Sphere.now()&amp;lt;/tt&amp;gt;''' [[API:Functions|Core API]] function returns the number of frames processed since the engine started running.&lt;br /&gt;
&lt;br /&gt;
===== Usage =====&lt;br /&gt;
&lt;br /&gt;
 ''frames_elapsed'' = '''Sphere.now'''();&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== API Information ==&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
'''&amp;lt;tt&amp;gt;Sphere.now()&amp;lt;/tt&amp;gt;''' returns the number of complete frames processed since the calling game started.  Therefore, on the very first frame this will return 0, on the next frame 1, and so on.  Specifically the return value is the number of full event loop turns, which by definition is the same as the number of updates performed.  This allows you to use &amp;lt;tt&amp;gt;Sphere.now()&amp;lt;/tt&amp;gt; as a frame-perfect timer in cases where using wall-clock time (e.g. &amp;lt;tt&amp;gt;Date.now()&amp;lt;/tt&amp;gt;) is not desirable.&lt;br /&gt;
&lt;br /&gt;
By default, Sphere will regulate updates so that 60 frames will be processed every second (60 FPS).  Your game can change that by setting the value of &amp;lt;tt&amp;gt;[[API:Sphere.frameRate|Sphere.frameRate]]&amp;lt;/tt&amp;gt; to something other than 60.&lt;br /&gt;
&lt;br /&gt;
=== Parameters ===&lt;br /&gt;
&lt;br /&gt;
This function has no parameters.&lt;br /&gt;
&lt;br /&gt;
=== Return Value ===&lt;br /&gt;
&lt;br /&gt;
The number of complete frames processed since the game started running.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;&lt;br /&gt;
* [[API:Sphere.frameRate|Sphere.frameRate]]&lt;br /&gt;
&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Sphere 2 API]]&lt;/div&gt;</summary>
		<author><name>Bruce Pascoe</name></author>	</entry>

	</feed>