Difference between revisions of "API:Sphere.now"
(Add Sphere.now() page)
Revision as of 16:32, 2 November 2017
The Sphere.now() Core API function returns the number of frames processed since the engine started running.
frames_elapsed = Sphere.now();
Sphere.now() 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 Sphere.now() as a frame-perfect timer in cases where using wall-clock time (e.g. Date.now()) is not desirable.
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 Sphere.frameRate to something other than 60.
This function has no parameters.
The number of complete frames processed since the game started running.