Class Rubygame::Time::Clock
In: lib/rubygame/clock.rb
Parent: Object

Clock provides an interface to the Time module methods, yielding a more convenient way to monitor and limit application framerate.

Methods

desired_mspf   desired_mspf=   fps   new   tick   time  

Attributes

desired_fps  [RW]  Access the desired number of frames per second. If this is set, tick will add a small delay to each frame to slow down execution if it is running faster than this value. If nil or false, no slowdown will be made to execution.

Public Class methods

Create a new Clock.

This method takes this argument:

desired_fps:the desired frames per second, used to limit framerate; if false or nil (default), no limiting will occur. Use the accessor @desired_fps to set or modify this value after the Clock has been initialized. See tick

Public Instance methods

Return the desired time (milliseconds) per frames. This is the same as 1000.0/@desired_fps.

Set the desired time (milliseconds) per frames. If this is set, tick will add a small delay to each frame to slow down execution if the natural delay between frames is too small. If nil or false, no slowdown will be made to execution.

This is an alternative to setting @desired_fps directly. You can get exactly the same effect by setting @desired_fps to 1000.0/dmspf.

Return frames per second (fps) recorded by the Clock

Call this function once per frame to use framerate tracking. Returns the number of milliseconds since the last time you called the function.

If @desired_fps is set, this function will delay execution for a certain amount of time so that (if you call this function once per frame) the program will run at that framerate.

The accuracy of this method is less than perfect (for me, it runs about 5-15 fps too quickly if the desired fps is less than 100 or so), but it‘s still useful.

(Please note that no effort is made to correct a framerate which is slower than the desired framerate, i.e. it can‘t make your code run any faster, only slow it down if it is running too quickly.)

Returns time in milliseconds since this Clock was initialized

[Validate]