mobile-graphic-easel-src-easeljs-utils-Ticker.js / js
The Ticker provides a centralized tick or heartbeat broadcast at a set interval. Listeners can subscribe to the tick event to be notified when a set time interval has elapsed. Note that the interval that the tick event is called is a target interval, and may be broadcast at a slower interval during times of high CPU load. The Ticker class uses a static interface (ex. <code>Ticker.getPaused()</code>) and should not be instantiated. <h4>Example</h4> createjs.Ticker.addEventListener("tick", handleTick); function handleTick(event) { // Actions carried out each frame if (!event.paused) { // Actions carried out when the Ticker is not paused. } } @class Ticker @uses EventDispatcher @static
Dispatched each tick. The event will be dispatched to each listener even when the Ticker has been paused using {{#crossLink "Ticker/setPaused"}}{{/crossLink}}. <h4>Example</h4> createjs.Ticker.addEventListener("tick", handleTick); function handleTick(event) { console.log("Paused:", event.paused, event.delta); } @event tick
parameter: {Object} target The object that dispatched the event.
parameter: {String} type The event type.
parameter: {Boolean} paused Indicates whether the ticker is currently paused.
parameter: {Number} delta The time elapsed in ms since the last tick.
parameter: {Number} time The total time in ms since Ticker was initialized.
parameter: {Number} runTime The total time in ms that Ticker was not paused since it was initialized. For example, you could determine the amount of time that the Ticker has been paused since initialization with time-runTime. @since 0.6.0
Indicates whether Ticker should use <code>requestAnimationFrame</code> if it is supported in the browser. If false, Ticker will use <code>setTimeout</code>. If you use RAF, it is recommended that you set the framerate to a divisor of 60 (ex. 15, 20, 30, 60). @property useRAF @static @type {Boolean} @default false
@property _listeners @type {Array} @protected
@property _pauseable @type {Array} @protected
@property _paused @type {Boolean} @protected
@property _inited @type {Boolean} @protected
@property _startTime @type {Number} @protected
@property _pausedTime @type {Number} @protected
The number of ticks that have passed @property _ticks @type {Number} @protected
The number of ticks that have passed while Ticker has been paused @property _pausedTicks @type {Number} @protected
@property _interval @type {Number} @protected
@property _lastTime @type {Number} @protected
@property _times @type {Array} @protected
@property _tickTimes @type {Array} @protected
@property _rafActive @type {Boolean} @protected
@property _timeoutID @type {Number} @protected
Adds a listener for the tick event. The listener must be either an object exposing a <code>tick</code> method, or a function. The listener will be called once each tick / interval. The interval is specified via the <code>.setInterval(ms)</code> method. The tick method or function is passed two parameters: the elapsed time between the previous tick and the current one, and a boolean indicating whether Ticker is paused. @method addListener @static
parameter: {Object} o The object or function to add as a listener.
parameter: {Boolean} pauseable If false, the listener will continue to have tick called even when Ticker is paused via Ticker.pause(). Default is true. @deprecated In favour of the "tick" event. Will be removed in a future version. User "addEventListener" instead.
Initializes or resets the timer, clearing all associated listeners and fps measuring data, starting the tick. This is called automatically when the first listener is added. @method init @static
Removes the specified listener. @method removeListener @static
parameter: {Object} o The object or function to remove from listening from the tick event. @deprecated In favour of the "tick" event. Will be removed in a future version. Use "removeEventListener" instead.
Removes all listeners. @method removeAllListeners @static @deprecated In favour of the "tick" event. Will be removed in a future version. Use "removeAllEventListeners" instead.
Sets the target time (in milliseconds) between ticks. Default is 50 (20 FPS). Note actual time between ticks may be more than requested depending on CPU load. @method setInterval @static
parameter: {Number} interval Time in milliseconds between ticks. Default value is 50.
Returns the current target time between ticks, as set with {{#crossLink "Ticker/setInterval"}}{{/crossLink}}. @method getInterval @static
returns: {Number} The current target interval in milliseconds between tick events.
Sets the target frame rate in frames per second (FPS). For example, with an interval of 40, <code>getFPS()</code> will return 25 (1000ms per second divided by 40 ms per tick = 25fps). @method setFPS @static
parameter: {Number} value Target number of ticks broadcast per second.
Returns the target frame rate in frames per second (FPS). For example, with an interval of 40, <code>getFPS()</code> will return 25 (1000ms per second divided by 40 ms per tick = 25fps). @method getFPS @static
returns: {Number} The current target number of frames / ticks broadcast per second.
Returns the actual frames / ticks per second. @method getMeasuredFPS @static
parameter: {Number} [ticks] The number of previous ticks over which to measure the actual frames / ticks per second. Defaults to the number of ticks per second.
returns: {Number} The actual frames / ticks per second. Depending on performance, this may differ from the target frames per second.
Changes the "paused" state of the Ticker, which can be retrieved by the {{#crossLink "Ticker/getPaused"}}{{/crossLink}} method, and is passed as the "paused" property of the <code>tick</code> event. When the ticker is paused, all listeners will still receive a tick event, but the <code>paused</code> property will be false. Note that in EaselJS v0.5.0 and earlier, "pauseable" listeners would <strong>not</strong> receive the tick callback when Ticker was paused. This is no longer the case. <h4>Example</h4> createjs.Ticker.addEventListener("tick", handleTick); createjs.Ticker.setPaused(true); function handleTick(event) { console.log("Paused:", event.paused, createjs.Ticker.getPaused()); } @method setPaused @static
parameter: {Boolean} value Indicates whether to pause (true) or unpause (false) Ticker.
Returns a boolean indicating whether Ticker is currently paused, as set with {{#crossLink "Ticker/setPaused"}}{{/crossLink}}. When the ticker is paused, all listeners will still receive a tick event, but this value will be false. Note that in EaselJS v0.5.0 and earlier, "pauseable" listeners would <strong>not</strong> receive the tick callback when Ticker was paused. This is no longer the case. <h4>Example</h4> createjs.Ticker.addEventListener("tick", handleTick); createjs.Ticker.setPaused(true); function handleTick(event) { console.log("Paused:", createjs.Ticker.getPaused()); } @static
returns: {Boolean} Whether the Ticker is currently paused.
Returns the number of milliseconds that have elapsed since Ticker was initialized. For example, you could use this in a time synchronized animation to determine the exact amount of time that has elapsed. @method getTime @static
parameter: {Boolean} [runTime=false] If true only time elapsed while Ticker was not paused will be returned. If false, the value returned will be total time elapsed since the first tick event listener was added.
returns: {Number} Number of milliseconds that have elapsed since Ticker was initialized.
Returns the number of ticks that have been broadcast by Ticker. @method getTicks @static
parameter: {Boolean} pauseable Indicates whether to include ticks that would have been broadcast while Ticker was paused. If true only tick events broadcast while Ticker is not paused will be returned. If false, tick events that would have been broadcast while Ticker was paused will be included in the return value. The default value is false.
returns: {Number} of ticks that have been broadcast.
@method _handleAF @protected
@method _handleTimeout @protected
@method _setupTick @protected
@method _tick @protected
@method _getTime @protected
(C) Æliens 04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.