From Spherical
Jump to: navigation, search

The Sphere.now() Core API function returns the number of frames processed since the engine started running.

frames_elapsed = Sphere.now();

API Information


Sphere.now() returns the number of complete event loop turns since the calling game started, each event loop turn corresponding to a frame. Therefore, on the very first frame this will return 0, on the next frame 1, and so on. Because Sphere.now() counts frames instead of wall-clock time, this allows you to use it as a frame-perfect timer, which is often more predictable than wall-clock time, particularly if the game begins dropping frames.

By default, Sphere regulates the event loop such that 60 frames are 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.

Return Value

The number of complete frames processed since the game started running. This value will roll over, like an odometer, after exactly 4,294,967,296 frames. 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.

See Also