Legacy:SetFrameRate

From Spherical
Revision as of 10:53, 10 June 2015 by DaVince (talk | contribs) (See also: added map engine framerate functions)
Jump to: navigation, search

Set or unset a limit to the refresh rate of drawing functions outside the map engine.

Usage

SetFrameRate(fps);


  • fps integer. Short for Frames Per Second, which limits how often the screen can be refreshed in one second
    sixty (60) is a common value for this
    If this is set to zero (0), no limit is imposed and the screen will update as fast as possible.

Examples

// Flashing screen example
var r = Math.random;	// for faster typing later
var f = GetSystemFont();

// === Set frame rate ===
SetFrameRate(5);

while (AreKeysLeft()) GetKey();
while (!AreKeysLeft())
{
  // Cheap screen coloring using ApplyColorMask()
  ApplyColorMask(CreateColor(r() * 255, r() * 255, r() * 255));
  f.drawText(0, 0, "fps = " + GetFrameRate());
  FlipScreen();
}
GetKey();

// === Change frame rate ===
SetFrameRate(30);

while (AreKeysLeft()) GetKey();
while (!AreKeysLeft())
{
  ApplyColorMask(CreateColor(r() * 255, r() * 255, r() * 255));
  f.drawText(0, 0, "fps = " + GetFrameRate());
  FlipScreen();
}
GetKey();

Flashing colors aside, note the difference in the speed of the top and bottom loops due to the previous calls to SetFrameRate() above. Here, GetFrameRate() is also used to illustrate how to obtain the current frame rate.

Notes

  • Though the main description implies that all drawing functions are affected by this, in fact only FlipScreen() is limited, or 'throttled'. For example, if SetFrameRate(30); were executed, FlipScreen() could be called at most 30 times in one second, with small, roughly even pauses to distribute the screen updates evenly.
  • GetFrameRate() can be used to obtain the current frame rate.
  • The frames per second set with this function are completely independent of that of the second argument of MapEngine(), and any functions that access or modify the map engine's frame rate.

See also

API:Video/navbox