Class: Ticker

Tiny.ticker. Ticker

A Ticker class that runs an update loop that other objects listen to.
This class is composed around listeners meant for execution on the next requested animation frame.
Animation frames are requested only when necessary, e.g. When the ticker is started and the emitter has listeners.

new Tiny.ticker.Ticker()

Members

autoStartboolean

Whether or not this ticker should invoke the method Tiny.ticker.Ticker#start automatically when a listener is added.

Default Value:
  • false

deltaTimenumber

Scalar time value from last frame to this frame.
This value is capped by setting Tiny.ticker.Ticker#minFPS and is scaled with Tiny.ticker.Ticker#speed.
Note: The cap may be exceeded by scaling.

Default Value:
  • 1

elapsedMSnumber

Time elapsed in milliseconds from last frame to this frame.
Opposed to what the scalar Tiny.ticker.Ticker#deltaTime is based, this value is neither capped nor scaled.
If the platform supports DOMHighResTimeStamp, this value will have a precision of 1 µs.
Defaults to target frame time

Default Value:
  • 16.66

lastTimenumber

The last time Tiny.ticker.Ticker#update was invoked.
This value is also reset internally outside of invoking update, but only when a new animation frame is requested.
If the platform supports DOMHighResTimeStamp, this value will have a precision of 1 µs.

Default Value:
  • -1

speednumber

Factor of current Tiny.ticker.Ticker#deltaTime.

Default Value:
  • 1
Example
// Scales ticker.deltaTime to what would be the equivalent of approximately 120 FPS
ticker.speed = 2;

startedboolean

Whether or not this ticker has been started. true if Tiny.ticker.Ticker#start has been called. false if Tiny.ticker.Ticker#stop has been called.
While false, this value may change to true in the event of Tiny.ticker.Ticker#autoStart being true and a listener is added.

Default Value:
  • false

Methods

add(fn, context, priority){Tiny.ticker.Ticker}

Register a handler for tick events. Calls continuously unless it is removed or the ticker is stopped.

Name Type Default Description
fn function

The listener function to be added for updates

context function optional

The listener context

priority number Tiny.UPDATE_PRIORITY.NORMAL optional

The priority for emitting

Returns:
Type Description
Tiny.ticker.Ticker This instance of a ticker

addOnce(fn, context, priority){Tiny.ticker.Ticker}

Add a handler for the tick event which is only execute once.

Name Type Default Description
fn function

The listener function to be added for one update

context function optional

The listener context

priority number Tiny.UPDATE_PRIORITY.NORMAL optional

The priority for emitting

Returns:
Type Description
Tiny.ticker.Ticker This instance of a ticker

定时触发,暂不支持 stop
注意:该方法已不推荐使用,请直接使用 Tiny.ticker.CountDown

Name Type Description
opts object
Name Type Description
duration number

间隔时长(单位:ms)

callback function
times number

次数,不传即无限次

complete function

完成后的回调

Version:
  • 1.0.2
Deprecated
  • since version 1.1.7

    Destroy the ticker and don't use after this. Calling this method removes all references to internal events.

    Removes any handlers matching the function and context parameters.
    If no handlers are left after removing, then it cancels the animation frame.

    Name Type Description
    fn function

    The listener function to be removed

    context function optional

    The listener context to be removed

    Returns:
    Type Description
    Tiny.ticker.Ticker This instance of a ticker

    Starts the ticker. If the ticker has listeners a new animation frame is requested at this point.

    Stops the ticker. If the ticker has requested an animation frame it is canceled at this point.

    update(currentTime)

    Triggers an update. An update entails setting the current Tiny.ticker.Ticker#elapsedMS, the current Tiny.ticker.Ticker#deltaTime, invoking all listeners with current deltaTime, and then finally setting Tiny.ticker.Ticker#lastTime with the value of currentTime that was provided.
    This method will be called automatically by animation frame callbacks if the ticker instance has been started and listeners are added.

    Name Type Default Description
    currentTime number window.performance.now() optional

    the current time of execution

    Documentation generated by JSDoc 3.4.3 on Mon Dec 03 2018 17:48:53 GMT+0800 (CST)