Difference between revisions of "Legacy:SetFrameRate"

From Spherical
Jump to: navigation, search
(filled)
m (Usage: NTSC/PAL note)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
Set or unset a limit to the refresh rate of drawing functions outside the map engine.
+
Set or unset a limit to the refresh rate of drawing functions outside the map engine. (So for anything relying on [[API:FlipScreen|FlipScreen]]() to render.)
  
 
__TOC__
 
__TOC__
Line 7: Line 7:
  
 
* '''fps''' integer. Short for '''F'''rames '''P'''er '''S'''econd, which limits how often the screen can be refreshed in one second
 
* '''fps''' integer. Short for '''F'''rames '''P'''er '''S'''econd, which limits how often the screen can be refreshed in one second
*: sixty (60) is a common value for this
+
*: sixty (60) is a common value for this in NTSC regions, fifty (50) in PAL regions.
 
*: If this is set to zero (0), no limit is imposed and the screen will update as fast as possible.
 
*: If this is set to zero (0), no limit is imposed and the screen will update as fast as possible.
  
Line 48: Line 48:
 
* [[API:GetFrameRate|GetFrameRate]]() can be used to obtain the current frame rate.
 
* [[API:GetFrameRate|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 [[API:MapEngine|MapEngine]](), and any functions that access or modify the map engine's frame rate.
 
* The frames per second set with this function are completely independent of that of the second argument of [[API:MapEngine|MapEngine]](), and any functions that access or modify the map engine's frame rate.
 +
* At high frame rates, the recommended value for FPS is 60, as this is the default refresh rate of most monitors on the market and will thus provide the smoothest visuals. Otherwise you might get [http://en.wikipedia.org/wiki/Screen_tearing screen tearing], depending on your video settings and Sphere implementation.
 +
** If you deliberately use a lower frame rate, you can prevent tearing by setting it to a value that you can multiply to 60. For example: 30, 20, 15, 12, 10.
  
 
==See also==
 
==See also==
 
* [[API:GetFrameRate|GetFrameRate]]()
 
* [[API:GetFrameRate|GetFrameRate]]()
 +
* [[API:SetMapEngineFrameRate|SetMapEngineFrameRate]]()
 +
* [[API:GetMapEngineFrameRate|GetMapEngineFrameRate]]()
 
* [[API:ApplyColorMask|ApplyColorMask]]()
 
* [[API:ApplyColorMask|ApplyColorMask]]()
 
* [[API:AreKeysLeft|AreKeysLeft]]()
 
* [[API:AreKeysLeft|AreKeysLeft]]()

Latest revision as of 05:25, 16 June 2015

Set or unset a limit to the refresh rate of drawing functions outside the map engine. (So for anything relying on FlipScreen() to render.)

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 in NTSC regions, fifty (50) in PAL regions.
    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.
  • At high frame rates, the recommended value for FPS is 60, as this is the default refresh rate of most monitors on the market and will thus provide the smoothest visuals. Otherwise you might get screen tearing, depending on your video settings and Sphere implementation.
    • If you deliberately use a lower frame rate, you can prevent tearing by setting it to a value that you can multiply to 60. For example: 30, 20, 15, 12, 10.

See also

API:Video/navbox