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:
- 0
-
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.
trueif Tiny.ticker.Ticker#start has been called.falseif Tiny.ticker.Ticker#stop has been called.
Whilefalse, this value may change totruein the event of Tiny.ticker.Ticker#autoStart beingtrue
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 fnfunction The listener function to be added for updates
contextfunction optional The listener context
prioritynumber 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 fnfunction The listener function to be added for one update
contextfunction optional The listener context
prioritynumber Tiny.UPDATE_PRIORITY.NORMAL optional The priority for emitting
Returns:
Type Description Tiny.ticker.Ticker This instance of a ticker -
countDown(opts)
-
定时触发,暂不支持 stop
注意:该方法已不推荐使用,请直接使用Tiny.ticker.CountDownName Type Description optsobject Name Type Description durationnumber 间隔时长(单位:ms)
callbackfunction timesnumber 次数,不传即无限次
completefunction 完成后的回调
- Version:
- 1.0.2
- Deprecated
- since version 1.1.7
-
destroy()
-
Destroy the ticker and don't use after this. Calling
this method removes all references to internal events. -
remove(fn, context) ❯ {Tiny.ticker.Ticker}
-
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 fnfunction The listener function to be removed
contextfunction optional The listener context to be removed
Returns:
Type Description Tiny.ticker.Ticker This instance of a ticker -
start()
-
Starts the ticker. If the ticker has listeners
a new animation frame is requested at this point. -
stop()
-
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 currentTimenumber performance.now() optional the current time of execution