Difference between revisions of "Legacy:SetFrameRate"

From Spherical
Jump to: navigation, search
(created from http://web.archive.org/web/20111228000549/http://www.spheredev.org/wiki/SetFrameRate)
 
(filled)
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.
  
Line 6: Line 4:
  
 
==Usage==
 
==Usage==
{{Usage|returns={{{returns}}}|object={{{object}}}|func=SetFrameRate|params=fps}}
+
{{Usage|func=SetFrameRate|params=fps}}
  
* '''param1''' type. param1 description
+
* '''fps''' integer. Short for '''F'''rames '''P'''er '''S'''econd, which limits how often the screen can be refreshed in one second
* '''param2''' type. param2 description
+
*: sixty (60) is a common value for this
* '''paramN''' type. paramN description
+
*: If this is set to zero (0), no limit is imposed and the screen will update as fast as possible.
  
 
==Examples==
 
==Examples==
(examples with syntaxhighlighted code)
+
<syntaxhighlight>
 +
// 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();
 +
</syntaxhighlight>
 +
 
 +
Flashing colors aside, note the difference in the speed of the top and bottom loops due to the previous calls to [[API:SetFrameRate|SetFrameRate]]() above. Here, [[API:GetFrameRate|GetFrameRate]]() is also used to illustrate how to obtain the current frame rate.
  
 
==Notes==
 
==Notes==
(notes)
+
* Though the main description implies that all drawing functions are affected by this, in fact only [[API:FlipScreen|FlipScreen]]() is limited, or 'throttled'. For example, if <code>SetFrameRate(30);</code> were executed, <code>FlipScreen()</code> could be called at most 30 times in one second, with small, roughly even pauses to distribute the screen updates evenly.
 +
* [[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.
  
 
==See also==
 
==See also==
* see also
+
* [[API:GetFrameRate|GetFrameRate]]()
* see also
+
* [[API:ApplyColorMask|ApplyColorMask]]()
* see also
+
* [[API:AreKeysLeft|AreKeysLeft]]()
* etc
+
* [[API:CreateColor|CreateColor]]()
 +
* [[API:FlipScreen|FlipScreen]]()
 +
* [[API:Font/drawText|Font.drawText]]()
 +
* [[API:GetKey|GetKey]]()
 +
* [[API:GetSystemFont|GetSystemFont]]()
 +
* [[API:MapEngine|MapEngine]]()
 +
* [[wikipedia:Frames per second|Frames per second]] on [http://www.wikipedia.org Wikipedia]
 +
* [https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Math/random Math.random]()
  
 
{{API:Video/navbox}}
 
{{API:Video/navbox}}

Revision as of 23:18, 24 June 2013

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