Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@pixi/ticker

Package Overview
Dependencies
Maintainers
3
Versions
118
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pixi/ticker - npm Package Compare versions

Comparing version 5.1.3 to 5.2.0

1518

dist/ticker.js
/*!
* @pixi/ticker - v5.1.3
* Compiled Mon, 09 Sep 2019 04:51:53 UTC
* @pixi/ticker - v5.2.0
* Compiled Wed, 06 Nov 2019 02:32:43 UTC
*

@@ -32,3 +32,3 @@ * @pixi/ticker is licensed under the MIT License.

* @memberof PIXI
* @type {object}
* @enum {number}
* @property {number} INTERACTION=50 Highest priority, used for {@link PIXI.interaction.InteractionManager}

@@ -40,9 +40,9 @@ * @property {number} HIGH=25 High priority updating, {@link PIXI.VideoBaseTexture} and {@link PIXI.AnimatedSprite}

*/
var UPDATE_PRIORITY = {
INTERACTION: 50,
HIGH: 25,
NORMAL: 0,
LOW: -25,
UTILITY: -50,
};
(function (UPDATE_PRIORITY) {
UPDATE_PRIORITY[UPDATE_PRIORITY["INTERACTION"] = 50] = "INTERACTION";
UPDATE_PRIORITY[UPDATE_PRIORITY["HIGH"] = 25] = "HIGH";
UPDATE_PRIORITY[UPDATE_PRIORITY["NORMAL"] = 0] = "NORMAL";
UPDATE_PRIORITY[UPDATE_PRIORITY["LOW"] = -25] = "LOW";
UPDATE_PRIORITY[UPDATE_PRIORITY["UTILITY"] = -50] = "UTILITY";
})(exports.UPDATE_PRIORITY || (exports.UPDATE_PRIORITY = {}));

@@ -56,162 +56,138 @@ /**

*/
var TickerListener = function TickerListener(fn, context, priority, once)
{
if ( context === void 0 ) context = null;
if ( priority === void 0 ) priority = 0;
if ( once === void 0 ) once = false;
var TickerListener = /** @class */ (function () {
/**
* The handler function to execute.
* Constructor
* @private
* @member {Function}
* @param {Function} fn - The listener function to be added for one update
* @param {*} [context=null] - The listener context
* @param {number} [priority=0] - The priority for emitting
* @param {boolean} [once=false] - If the handler should fire once
*/
this.fn = fn;
function TickerListener(fn, context, priority, once) {
if (context === void 0) { context = null; }
if (priority === void 0) { priority = 0; }
if (once === void 0) { once = false; }
/**
* The handler function to execute.
* @private
* @member {Function}
*/
this.fn = fn;
/**
* The calling to execute.
* @private
* @member {*}
*/
this.context = context;
/**
* The current priority.
* @private
* @member {number}
*/
this.priority = priority;
/**
* If this should only execute once.
* @private
* @member {boolean}
*/
this.once = once;
/**
* The next item in chain.
* @private
* @member {TickerListener}
*/
this.next = null;
/**
* The previous item in chain.
* @private
* @member {TickerListener}
*/
this.previous = null;
/**
* `true` if this listener has been destroyed already.
* @member {boolean}
* @private
*/
this._destroyed = false;
}
/**
* The calling to execute.
* Simple compare function to figure out if a function and context match.
* @private
* @member {*}
* @param {Function} fn - The listener function to be added for one update
* @param {any} [context] - The listener context
* @return {boolean} `true` if the listener match the arguments
*/
this.context = context;
TickerListener.prototype.match = function (fn, context) {
if (context === void 0) { context = null; }
return this.fn === fn && this.context === context;
};
/**
* The current priority.
* Emit by calling the current function.
* @private
* @member {number}
* @param {number} deltaTime - time since the last emit.
* @return {TickerListener} Next ticker
*/
this.priority = priority;
TickerListener.prototype.emit = function (deltaTime) {
if (this.fn) {
if (this.context) {
this.fn.call(this.context, deltaTime);
}
else {
this.fn(deltaTime);
}
}
var redirect = this.next;
if (this.once) {
this.destroy(true);
}
// Soft-destroying should remove
// the next reference
if (this._destroyed) {
this.next = null;
}
return redirect;
};
/**
* If this should only execute once.
* Connect to the list.
* @private
* @member {boolean}
* @param {TickerListener} previous - Input node, previous listener
*/
this.once = once;
TickerListener.prototype.connect = function (previous) {
this.previous = previous;
if (previous.next) {
previous.next.previous = this;
}
this.next = previous.next;
previous.next = this;
};
/**
* The next item in chain.
* Destroy and don't use after this.
* @private
* @member {TickerListener}
* @param {boolean} [hard = false] `true` to remove the `next` reference, this
* is considered a hard destroy. Soft destroy maintains the next reference.
* @return {TickerListener} The listener to redirect while emitting or removing.
*/
this.next = null;
/**
* The previous item in chain.
* @private
* @member {TickerListener}
*/
this.previous = null;
/**
* `true` if this listener has been destroyed already.
* @member {boolean}
* @private
*/
this._destroyed = false;
};
/**
* Simple compare function to figure out if a function and context match.
* @private
* @param {Function} fn - The listener function to be added for one update
* @param {Function} context - The listener context
* @return {boolean} `true` if the listener match the arguments
*/
TickerListener.prototype.match = function match (fn, context)
{
context = context || null;
return this.fn === fn && this.context === context;
};
/**
* Emit by calling the current function.
* @private
* @param {number} deltaTime - time since the last emit.
* @return {TickerListener} Next ticker
*/
TickerListener.prototype.emit = function emit (deltaTime)
{
if (this.fn)
{
if (this.context)
{
this.fn.call(this.context, deltaTime);
TickerListener.prototype.destroy = function (hard) {
if (hard === void 0) { hard = false; }
this._destroyed = true;
this.fn = null;
this.context = null;
// Disconnect, hook up next and previous
if (this.previous) {
this.previous.next = this.next;
}
else
{
this.fn(deltaTime);
if (this.next) {
this.next.previous = this.previous;
}
}
// Redirect to the next item
var redirect = this.next;
// Remove references
this.next = hard ? null : redirect;
this.previous = null;
return redirect;
};
return TickerListener;
}());
var redirect = this.next;
if (this.once)
{
this.destroy(true);
}
// Soft-destroying should remove
// the next reference
if (this._destroyed)
{
this.next = null;
}
return redirect;
};
/**
* Connect to the list.
* @private
* @param {TickerListener} previous - Input node, previous listener
*/
TickerListener.prototype.connect = function connect (previous)
{
this.previous = previous;
if (previous.next)
{
previous.next.previous = this;
}
this.next = previous.next;
previous.next = this;
};
/**
* Destroy and don't use after this.
* @private
* @param {boolean} [hard = false] `true` to remove the `next` reference, this
* is considered a hard destroy. Soft destroy maintains the next reference.
* @return {TickerListener} The listener to redirect while emitting or removing.
*/
TickerListener.prototype.destroy = function destroy (hard)
{
if ( hard === void 0 ) hard = false;
this._destroyed = true;
this.fn = null;
this.context = null;
// Disconnect, hook up next and previous
if (this.previous)
{
this.previous.next = this.next;
}
if (this.next)
{
this.next.previous = this.previous;
}
// Redirect to the next item
var redirect = this.next;
// Remove references
this.next = hard ? null : redirect;
this.previous = null;
return redirect;
};
/**
* A Ticker class that runs an update loop that other objects listen to.

@@ -225,631 +201,532 @@ *

*/
var Ticker = function Ticker()
{
var this$1 = this;
var Ticker = /** @class */ (function () {
function Ticker() {
var _this = this;
/**
* The first listener. All new listeners added are chained on this.
* @private
* @type {TickerListener}
*/
this._head = new TickerListener(null, null, Infinity);
/**
* Internal current frame request ID
* @type {?number}
* @private
*/
this._requestId = null;
/**
* Internal value managed by minFPS property setter and getter.
* This is the maximum allowed milliseconds between updates.
* @type {number}
* @private
*/
this._maxElapsedMS = 100;
/**
* Internal value managed by maxFPS property setter and getter.
* This is the minimum allowed milliseconds between updates.
* @type {number}
* @private
*/
this._minElapsedMS = 0;
/**
* Whether or not this ticker should invoke the method
* {@link PIXI.Ticker#start} automatically
* when a listener is added.
*
* @member {boolean}
* @default false
*/
this.autoStart = false;
/**
* Scalar time value from last frame to this frame.
* This value is capped by setting {@link PIXI.Ticker#minFPS}
* and is scaled with {@link PIXI.Ticker#speed}.
* **Note:** The cap may be exceeded by scaling.
*
* @member {number}
* @default 1
*/
this.deltaTime = 1;
/**
* Scaler time elapsed in milliseconds from last frame to this frame.
* This value is capped by setting {@link PIXI.Ticker#minFPS}
* and is scaled with {@link PIXI.Ticker#speed}.
* **Note:** The cap may be exceeded by scaling.
* If the platform supports DOMHighResTimeStamp,
* this value will have a precision of 1 µs.
* Defaults to target frame time
*
* @member {number}
* @default 16.66
*/
this.deltaMS = 1 / settings.settings.TARGET_FPMS;
/**
* Time elapsed in milliseconds from last frame to this frame.
* Opposed to what the scalar {@link PIXI.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
*
* @member {number}
* @default 16.66
*/
this.elapsedMS = 1 / settings.settings.TARGET_FPMS;
/**
* The last time {@link PIXI.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.
*
* @member {number}
* @default -1
*/
this.lastTime = -1;
/**
* Factor of current {@link PIXI.Ticker#deltaTime}.
* @example
* // Scales ticker.deltaTime to what would be
* // the equivalent of approximately 120 FPS
* ticker.speed = 2;
*
* @member {number}
* @default 1
*/
this.speed = 1;
/**
* Whether or not this ticker has been started.
* `true` if {@link PIXI.Ticker#start} has been called.
* `false` if {@link PIXI.Ticker#stop} has been called.
* While `false`, this value may change to `true` in the
* event of {@link PIXI.Ticker#autoStart} being `true`
* and a listener is added.
*
* @member {boolean}
* @default false
*/
this.started = false;
/**
* If enabled, deleting is disabled.
* @member {boolean}
* @default false
* @private
*/
this._protected = false;
/**
* The last time keyframe was executed.
* Maintains a relatively fixed interval with the previous value.
* @member {number}
* @default -1
* @private
*/
this._lastFrame = -1;
/**
* Internal tick method bound to ticker instance.
* This is because in early 2015, Function.bind
* is still 60% slower in high performance scenarios.
* Also separating frame requests from update method
* so listeners may be called at any time and with
* any animation API, just invoke ticker.update(time).
*
* @private
* @param {number} time - Time since last tick.
*/
this._tick = function (time) {
_this._requestId = null;
if (_this.started) {
// Invoke listeners now
_this.update(time);
// Listener side effects may have modified ticker state.
if (_this.started && _this._requestId === null && _this._head.next) {
_this._requestId = requestAnimationFrame(_this._tick);
}
}
};
}
/**
* The first listener. All new listeners added are chained on this.
* Conditionally requests a new animation frame.
* If a frame has not already been requested, and if the internal
* emitter has listeners, a new frame is requested.
*
* @private
* @type {TickerListener}
*/
this._head = new TickerListener(null, null, Infinity);
Ticker.prototype._requestIfNeeded = function () {
if (this._requestId === null && this._head.next) {
// ensure callbacks get correct delta
this.lastTime = performance.now();
this._lastFrame = this.lastTime;
this._requestId = requestAnimationFrame(this._tick);
}
};
/**
* Internal current frame request ID
* @type {?number}
* Conditionally cancels a pending animation frame.
*
* @private
*/
this._requestId = null;
Ticker.prototype._cancelIfNeeded = function () {
if (this._requestId !== null) {
cancelAnimationFrame(this._requestId);
this._requestId = null;
}
};
/**
* Internal value managed by minFPS property setter and getter.
* This is the maximum allowed milliseconds between updates.
* @type {number}
* Conditionally requests a new animation frame.
* If the ticker has been started it checks if a frame has not already
* been requested, and if the internal emitter has listeners. If these
* conditions are met, a new frame is requested. If the ticker has not
* been started, but autoStart is `true`, then the ticker starts now,
* and continues with the previous conditions to request a new frame.
*
* @private
*/
this._maxElapsedMS = 100;
Ticker.prototype._startIfPossible = function () {
if (this.started) {
this._requestIfNeeded();
}
else if (this.autoStart) {
this.start();
}
};
/**
* Internal value managed by maxFPS property setter and getter.
* This is the minimum allowed milliseconds between updates.
* @private
*/
this._minElapsedMS = 0;
/**
* Whether or not this ticker should invoke the method
* {@link PIXI.Ticker#start} automatically
* when a listener is added.
* Register a handler for tick events. Calls continuously unless
* it is removed or the ticker is stopped.
*
* @member {boolean}
* @default false
* @param {Function} fn - The listener function to be added for updates
* @param {*} [context] - The listener context
* @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting
* @returns {PIXI.Ticker} This instance of a ticker
*/
this.autoStart = false;
Ticker.prototype.add = function (fn, context, priority) {
if (priority === void 0) { priority = exports.UPDATE_PRIORITY.NORMAL; }
return this._addListener(new TickerListener(fn, context, priority));
};
/**
* Scalar time value from last frame to this frame.
* This value is capped by setting {@link PIXI.Ticker#minFPS}
* and is scaled with {@link PIXI.Ticker#speed}.
* **Note:** The cap may be exceeded by scaling.
* Add a handler for the tick event which is only execute once.
*
* @member {number}
* @default 1
* @param {Function} fn - The listener function to be added for one update
* @param {*} [context] - The listener context
* @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting
* @returns {PIXI.Ticker} This instance of a ticker
*/
this.deltaTime = 1;
Ticker.prototype.addOnce = function (fn, context, priority) {
if (priority === void 0) { priority = exports.UPDATE_PRIORITY.NORMAL; }
return this._addListener(new TickerListener(fn, context, priority, true));
};
/**
* Scaler time elapsed in milliseconds from last frame to this frame.
* This value is capped by setting {@link PIXI.Ticker#minFPS}
* and is scaled with {@link PIXI.Ticker#speed}.
* **Note:** The cap may be exceeded by scaling.
* If the platform supports DOMHighResTimeStamp,
* this value will have a precision of 1 µs.
* Defaults to target frame time
* Internally adds the event handler so that it can be sorted by priority.
* Priority allows certain handler (user, AnimatedSprite, Interaction) to be run
* before the rendering.
*
* @member {number}
* @default 16.66
* @private
* @param {TickerListener} listener - Current listener being added.
* @returns {PIXI.Ticker} This instance of a ticker
*/
this.deltaMS = 1 / settings.settings.TARGET_FPMS;
Ticker.prototype._addListener = function (listener) {
// For attaching to head
var current = this._head.next;
var previous = this._head;
// Add the first item
if (!current) {
listener.connect(previous);
}
else {
// Go from highest to lowest priority
while (current) {
if (listener.priority > current.priority) {
listener.connect(previous);
break;
}
previous = current;
current = current.next;
}
// Not yet connected
if (!listener.previous) {
listener.connect(previous);
}
}
this._startIfPossible();
return this;
};
/**
* Time elapsed in milliseconds from last frame to this frame.
* Opposed to what the scalar {@link PIXI.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
* Removes any handlers matching the function and context parameters.
* If no handlers are left after removing, then it cancels the animation frame.
*
* @member {number}
* @default 16.66
* @param {Function} fn - The listener function to be removed
* @param {*} [context] - The listener context to be removed
* @returns {PIXI.Ticker} This instance of a ticker
*/
this.elapsedMS = 1 / settings.settings.TARGET_FPMS;
Ticker.prototype.remove = function (fn, context) {
var listener = this._head.next;
while (listener) {
// We found a match, lets remove it
// no break to delete all possible matches
// incase a listener was added 2+ times
if (listener.match(fn, context)) {
listener = listener.destroy();
}
else {
listener = listener.next;
}
}
if (!this._head.next) {
this._cancelIfNeeded();
}
return this;
};
/**
* The last time {@link PIXI.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.
*
* @member {number}
* @default -1
* Starts the ticker. If the ticker has listeners
* a new animation frame is requested at this point.
*/
this.lastTime = -1;
Ticker.prototype.start = function () {
if (!this.started) {
this.started = true;
this._requestIfNeeded();
}
};
/**
* Factor of current {@link PIXI.Ticker#deltaTime}.
* @example
* // Scales ticker.deltaTime to what would be
* // the equivalent of approximately 120 FPS
* ticker.speed = 2;
*
* @member {number}
* @default 1
* Stops the ticker. If the ticker has requested
* an animation frame it is canceled at this point.
*/
this.speed = 1;
Ticker.prototype.stop = function () {
if (this.started) {
this.started = false;
this._cancelIfNeeded();
}
};
/**
* Whether or not this ticker has been started.
* `true` if {@link PIXI.Ticker#start} has been called.
* `false` if {@link PIXI.Ticker#stop} has been called.
* While `false`, this value may change to `true` in the
* event of {@link PIXI.Ticker#autoStart} being `true`
* and a listener is added.
*
* @member {boolean}
* @default false
* Destroy the ticker and don't use after this. Calling
* this method removes all references to internal events.
*/
this.started = false;
Ticker.prototype.destroy = function () {
if (!this._protected) {
this.stop();
var listener = this._head.next;
while (listener) {
listener = listener.destroy(true);
}
this._head.destroy();
this._head = null;
}
};
/**
* If enabled, deleting is disabled.
* @member {boolean}
* @default false
* @private
*/
this._protected = false;
/**
* The last time keyframe was executed.
* Maintains a relatively fixed interval with the previous value.
* @member {number}
* @default -1
* @private
*/
this._lastFrame = -1;
/**
* Internal tick method bound to ticker instance.
* This is because in early 2015, Function.bind
* is still 60% slower in high performance scenarios.
* Also separating frame requests from update method
* so listeners may be called at any time and with
* any animation API, just invoke ticker.update(time).
* Triggers an update. An update entails setting the
* current {@link PIXI.Ticker#elapsedMS},
* the current {@link PIXI.Ticker#deltaTime},
* invoking all listeners with current deltaTime,
* and then finally setting {@link PIXI.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.
*
* @private
* @param {number} time - Time since last tick.
* @param {number} [currentTime=performance.now()] - the current time of execution
*/
this._tick = function (time) {
this$1._requestId = null;
if (this$1.started)
{
// Invoke listeners now
this$1.update(time);
// Listener side effects may have modified ticker state.
if (this$1.started && this$1._requestId === null && this$1._head.next)
{
this$1._requestId = requestAnimationFrame(this$1._tick);
Ticker.prototype.update = function (currentTime) {
if (currentTime === void 0) { currentTime = performance.now(); }
var elapsedMS;
// If the difference in time is zero or negative, we ignore most of the work done here.
// If there is no valid difference, then should be no reason to let anyone know about it.
// A zero delta, is exactly that, nothing should update.
//
// The difference in time can be negative, and no this does not mean time traveling.
// This can be the result of a race condition between when an animation frame is requested
// on the current JavaScript engine event loop, and when the ticker's start method is invoked
// (which invokes the internal _requestIfNeeded method). If a frame is requested before
// _requestIfNeeded is invoked, then the callback for the animation frame the ticker requests,
// can receive a time argument that can be less than the lastTime value that was set within
// _requestIfNeeded. This difference is in microseconds, but this is enough to cause problems.
//
// This check covers this browser engine timing issue, as well as if consumers pass an invalid
// currentTime value. This may happen if consumers opt-out of the autoStart, and update themselves.
if (currentTime > this.lastTime) {
// Save uncapped elapsedMS for measurement
elapsedMS = this.elapsedMS = currentTime - this.lastTime;
// cap the milliseconds elapsed used for deltaTime
if (elapsedMS > this._maxElapsedMS) {
elapsedMS = this._maxElapsedMS;
}
}
};
};
var prototypeAccessors = { FPS: { configurable: true },minFPS: { configurable: true },maxFPS: { configurable: true } };
var staticAccessors = { shared: { configurable: true },system: { configurable: true } };
/**
* Conditionally requests a new animation frame.
* If a frame has not already been requested, and if the internal
* emitter has listeners, a new frame is requested.
*
* @private
*/
Ticker.prototype._requestIfNeeded = function _requestIfNeeded ()
{
if (this._requestId === null && this._head.next)
{
// ensure callbacks get correct delta
this.lastTime = performance.now();
this._lastFrame = this.lastTime;
this._requestId = requestAnimationFrame(this._tick);
}
};
/**
* Conditionally cancels a pending animation frame.
*
* @private
*/
Ticker.prototype._cancelIfNeeded = function _cancelIfNeeded ()
{
if (this._requestId !== null)
{
cancelAnimationFrame(this._requestId);
this._requestId = null;
}
};
/**
* Conditionally requests a new animation frame.
* If the ticker has been started it checks if a frame has not already
* been requested, and if the internal emitter has listeners. If these
* conditions are met, a new frame is requested. If the ticker has not
* been started, but autoStart is `true`, then the ticker starts now,
* and continues with the previous conditions to request a new frame.
*
* @private
*/
Ticker.prototype._startIfPossible = function _startIfPossible ()
{
if (this.started)
{
this._requestIfNeeded();
}
else if (this.autoStart)
{
this.start();
}
};
/**
* Register a handler for tick events. Calls continuously unless
* it is removed or the ticker is stopped.
*
* @param {Function} fn - The listener function to be added for updates
* @param {*} [context] - The listener context
* @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting
* @returns {PIXI.Ticker} This instance of a ticker
*/
Ticker.prototype.add = function add (fn, context, priority)
{
if ( priority === void 0 ) priority = UPDATE_PRIORITY.NORMAL;
return this._addListener(new TickerListener(fn, context, priority));
};
/**
* Add a handler for the tick event which is only execute once.
*
* @param {Function} fn - The listener function to be added for one update
* @param {*} [context] - The listener context
* @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting
* @returns {PIXI.Ticker} This instance of a ticker
*/
Ticker.prototype.addOnce = function addOnce (fn, context, priority)
{
if ( priority === void 0 ) priority = UPDATE_PRIORITY.NORMAL;
return this._addListener(new TickerListener(fn, context, priority, true));
};
/**
* Internally adds the event handler so that it can be sorted by priority.
* Priority allows certain handler (user, AnimatedSprite, Interaction) to be run
* before the rendering.
*
* @private
* @param {TickerListener} listener - Current listener being added.
* @returns {PIXI.Ticker} This instance of a ticker
*/
Ticker.prototype._addListener = function _addListener (listener)
{
// For attaching to head
var current = this._head.next;
var previous = this._head;
// Add the first item
if (!current)
{
listener.connect(previous);
}
else
{
// Go from highest to lowest priority
while (current)
{
if (listener.priority > current.priority)
{
listener.connect(previous);
break;
elapsedMS *= this.speed;
// If not enough time has passed, exit the function.
// Get ready for next frame by setting _lastFrame, but based on _minElapsedMS
// adjustment to ensure a relatively stable interval.
if (this._minElapsedMS) {
var delta = currentTime - this._lastFrame | 0;
if (delta < this._minElapsedMS) {
return;
}
this._lastFrame = currentTime - (delta % this._minElapsedMS);
}
previous = current;
current = current.next;
this.deltaMS = elapsedMS;
this.deltaTime = this.deltaMS * settings.settings.TARGET_FPMS;
// Cache a local reference, in-case ticker is destroyed
// during the emit, we can still check for head.next
var head = this._head;
// Invoke listeners added to internal emitter
var listener = head.next;
while (listener) {
listener = listener.emit(this.deltaTime);
}
if (!head.next) {
this._cancelIfNeeded();
}
}
// Not yet connected
if (!listener.previous)
{
listener.connect(previous);
else {
this.deltaTime = this.deltaMS = this.elapsedMS = 0;
}
}
this._startIfPossible();
return this;
};
/**
* Removes any handlers matching the function and context parameters.
* If no handlers are left after removing, then it cancels the animation frame.
*
* @param {Function} fn - The listener function to be removed
* @param {*} [context] - The listener context to be removed
* @returns {PIXI.Ticker} This instance of a ticker
*/
Ticker.prototype.remove = function remove (fn, context)
{
var listener = this._head.next;
while (listener)
{
// We found a match, lets remove it
// no break to delete all possible matches
// incase a listener was added 2+ times
if (listener.match(fn, context))
{
listener = listener.destroy();
}
else
{
listener = listener.next;
}
}
if (!this._head.next)
{
this._cancelIfNeeded();
}
return this;
};
/**
* Starts the ticker. If the ticker has listeners
* a new animation frame is requested at this point.
*/
Ticker.prototype.start = function start ()
{
if (!this.started)
{
this.started = true;
this._requestIfNeeded();
}
};
/**
* Stops the ticker. If the ticker has requested
* an animation frame it is canceled at this point.
*/
Ticker.prototype.stop = function stop ()
{
if (this.started)
{
this.started = false;
this._cancelIfNeeded();
}
};
/**
* Destroy the ticker and don't use after this. Calling
* this method removes all references to internal events.
*/
Ticker.prototype.destroy = function destroy ()
{
if (!this._protected)
{
this.stop();
var listener = this._head.next;
while (listener)
{
listener = listener.destroy(true);
}
this._head.destroy();
this._head = null;
}
};
/**
* Triggers an update. An update entails setting the
* current {@link PIXI.Ticker#elapsedMS},
* the current {@link PIXI.Ticker#deltaTime},
* invoking all listeners with current deltaTime,
* and then finally setting {@link PIXI.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.
*
* @param {number} [currentTime=performance.now()] - the current time of execution
*/
Ticker.prototype.update = function update (currentTime)
{
if ( currentTime === void 0 ) currentTime = performance.now();
var elapsedMS;
// If the difference in time is zero or negative, we ignore most of the work done here.
// If there is no valid difference, then should be no reason to let anyone know about it.
// A zero delta, is exactly that, nothing should update.
//
// The difference in time can be negative, and no this does not mean time traveling.
// This can be the result of a race condition between when an animation frame is requested
// on the current JavaScript engine event loop, and when the ticker's start method is invoked
// (which invokes the internal _requestIfNeeded method). If a frame is requested before
// _requestIfNeeded is invoked, then the callback for the animation frame the ticker requests,
// can receive a time argument that can be less than the lastTime value that was set within
// _requestIfNeeded. This difference is in microseconds, but this is enough to cause problems.
//
// This check covers this browser engine timing issue, as well as if consumers pass an invalid
// currentTime value. This may happen if consumers opt-out of the autoStart, and update themselves.
if (currentTime > this.lastTime)
{
// Save uncapped elapsedMS for measurement
elapsedMS = this.elapsedMS = currentTime - this.lastTime;
// cap the milliseconds elapsed used for deltaTime
if (elapsedMS > this._maxElapsedMS)
{
elapsedMS = this._maxElapsedMS;
}
elapsedMS *= this.speed;
// If not enough time has passed, exit the function.
// Get ready for next frame by setting _lastFrame, but based on _minElapsedMS
// adjustment to ensure a relatively stable interval.
if (this._minElapsedMS)
{
var delta = currentTime - this._lastFrame | 0;
if (delta < this._minElapsedMS)
{
return;
this.lastTime = currentTime;
};
Object.defineProperty(Ticker.prototype, "FPS", {
/**
* The frames per second at which this ticker is running.
* The default is approximately 60 in most modern browsers.
* **Note:** This does not factor in the value of
* {@link PIXI.Ticker#speed}, which is specific
* to scaling {@link PIXI.Ticker#deltaTime}.
*
* @member {number}
* @readonly
*/
get: function () {
return 1000 / this.elapsedMS;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Ticker.prototype, "minFPS", {
/**
* Manages the maximum amount of milliseconds allowed to
* elapse between invoking {@link PIXI.Ticker#update}.
* This value is used to cap {@link PIXI.Ticker#deltaTime},
* but does not effect the measured value of {@link PIXI.Ticker#FPS}.
* When setting this property it is clamped to a value between
* `0` and `PIXI.settings.TARGET_FPMS * 1000`.
*
* @member {number}
* @default 10
*/
get: function () {
return 1000 / this._maxElapsedMS;
},
set: function (fps) {
// Minimum must be below the maxFPS
var minFPS = Math.min(this.maxFPS, fps);
// Must be at least 0, but below 1 / settings.TARGET_FPMS
var minFPMS = Math.min(Math.max(0, minFPS) / 1000, settings.settings.TARGET_FPMS);
this._maxElapsedMS = 1 / minFPMS;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Ticker.prototype, "maxFPS", {
/**
* Manages the minimum amount of milliseconds required to
* elapse between invoking {@link PIXI.Ticker#update}.
* This will effect the measured value of {@link PIXI.Ticker#FPS}.
* If it is set to `0`, then there is no limit; PixiJS will render as many frames as it can.
* Otherwise it will be at least `minFPS`
*
* @member {number}
* @default 0
*/
get: function () {
if (this._minElapsedMS) {
return Math.round(1000 / this._minElapsedMS);
}
return 0;
},
set: function (fps) {
if (fps === 0) {
this._minElapsedMS = 0;
}
else {
// Max must be at least the minFPS
var maxFPS = Math.max(this.minFPS, fps);
this._minElapsedMS = 1 / (maxFPS / 1000);
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(Ticker, "shared", {
/**
* The shared ticker instance used by {@link PIXI.AnimatedSprite} and by
* {@link PIXI.VideoResource} to update animation frames / video textures.
*
* It may also be used by {@link PIXI.Application} if created with the `sharedTicker` option property set to true.
*
* The property {@link PIXI.Ticker#autoStart} is set to `true` for this instance.
* Please follow the examples for usage, including how to opt-out of auto-starting the shared ticker.
*
* @example
* let ticker = PIXI.Ticker.shared;
* // Set this to prevent starting this ticker when listeners are added.
* // By default this is true only for the PIXI.Ticker.shared instance.
* ticker.autoStart = false;
* // FYI, call this to ensure the ticker is stopped. It should be stopped
* // if you have not attempted to render anything yet.
* ticker.stop();
* // Call this when you are ready for a running shared ticker.
* ticker.start();
*
* @example
* // You may use the shared ticker to render...
* let renderer = PIXI.autoDetectRenderer();
* let stage = new PIXI.Container();
* document.body.appendChild(renderer.view);
* ticker.add(function (time) {
* renderer.render(stage);
* });
*
* @example
* // Or you can just update it manually.
* ticker.autoStart = false;
* ticker.stop();
* function animate(time) {
* ticker.update(time);
* renderer.render(stage);
* requestAnimationFrame(animate);
* }
* animate(performance.now());
*
* @member {PIXI.Ticker}
* @static
*/
get: function () {
if (!Ticker._shared) {
var shared = Ticker._shared = new Ticker();
shared.autoStart = true;
shared._protected = true;
}
return Ticker._shared;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Ticker, "system", {
/**
* The system ticker instance used by {@link PIXI.interaction.InteractionManager} and by
* {@link PIXI.BasePrepare} for core timing functionality that shouldn't usually need to be paused,
* unlike the `shared` ticker which drives visual animations and rendering which may want to be paused.
*
* The property {@link PIXI.Ticker#autoStart} is set to `true` for this instance.
*
* @member {PIXI.Ticker}
* @static
*/
get: function () {
if (!Ticker._system) {
var system = Ticker._system = new Ticker();
system.autoStart = true;
system._protected = true;
}
return Ticker._system;
},
enumerable: true,
configurable: true
});
return Ticker;
}());
this._lastFrame = currentTime - (delta % this._minElapsedMS);
}
this.deltaMS = elapsedMS;
this.deltaTime = this.deltaMS * settings.settings.TARGET_FPMS;
// Cache a local reference, in-case ticker is destroyed
// during the emit, we can still check for head.next
var head = this._head;
// Invoke listeners added to internal emitter
var listener = head.next;
while (listener)
{
listener = listener.emit(this.deltaTime);
}
if (!head.next)
{
this._cancelIfNeeded();
}
}
else
{
this.deltaTime = this.deltaMS = this.elapsedMS = 0;
}
this.lastTime = currentTime;
};
/**
* The frames per second at which this ticker is running.
* The default is approximately 60 in most modern browsers.
* **Note:** This does not factor in the value of
* {@link PIXI.Ticker#speed}, which is specific
* to scaling {@link PIXI.Ticker#deltaTime}.
*
* @member {number}
* @readonly
*/
prototypeAccessors.FPS.get = function ()
{
return 1000 / this.elapsedMS;
};
/**
* Manages the maximum amount of milliseconds allowed to
* elapse between invoking {@link PIXI.Ticker#update}.
* This value is used to cap {@link PIXI.Ticker#deltaTime},
* but does not effect the measured value of {@link PIXI.Ticker#FPS}.
* When setting this property it is clamped to a value between
* `0` and `PIXI.settings.TARGET_FPMS * 1000`.
*
* @member {number}
* @default 10
*/
prototypeAccessors.minFPS.get = function ()
{
return 1000 / this._maxElapsedMS;
};
prototypeAccessors.minFPS.set = function (fps) // eslint-disable-line require-jsdoc
{
// Minimum must be below the maxFPS
var minFPS = Math.min(this.maxFPS, fps);
// Must be at least 0, but below 1 / settings.TARGET_FPMS
var minFPMS = Math.min(Math.max(0, minFPS) / 1000, settings.settings.TARGET_FPMS);
this._maxElapsedMS = 1 / minFPMS;
};
/**
* Manages the minimum amount of milliseconds required to
* elapse between invoking {@link PIXI.Ticker#update}.
* This will effect the measured value of {@link PIXI.Ticker#FPS}.
* If it is set to `0`, then there is no limit; PixiJS will render as many frames as it can.
* Otherwise it will be at least `minFPS`
*
* @member {number}
* @default 0
*/
prototypeAccessors.maxFPS.get = function ()
{
if (this._minElapsedMS)
{
return Math.round(1000 / this._minElapsedMS);
}
return 0;
};
prototypeAccessors.maxFPS.set = function (fps)
{
if (fps === 0)
{
this._minElapsedMS = 0;
}
else
{
// Max must be at least the minFPS
var maxFPS = Math.max(this.minFPS, fps);
this._minElapsedMS = 1 / (maxFPS / 1000);
}
};
/**
* The shared ticker instance used by {@link PIXI.AnimatedSprite} and by
* {@link PIXI.VideoResource} to update animation frames / video textures.
*
* It may also be used by {@link PIXI.Application} if created with the `sharedTicker` option property set to true.
*
* The property {@link PIXI.Ticker#autoStart} is set to `true` for this instance.
* Please follow the examples for usage, including how to opt-out of auto-starting the shared ticker.
*
* @example
* let ticker = PIXI.Ticker.shared;
* // Set this to prevent starting this ticker when listeners are added.
* // By default this is true only for the PIXI.Ticker.shared instance.
* ticker.autoStart = false;
* // FYI, call this to ensure the ticker is stopped. It should be stopped
* // if you have not attempted to render anything yet.
* ticker.stop();
* // Call this when you are ready for a running shared ticker.
* ticker.start();
*
* @example
* // You may use the shared ticker to render...
* let renderer = PIXI.autoDetectRenderer();
* let stage = new PIXI.Container();
* document.body.appendChild(renderer.view);
* ticker.add(function (time) {
* renderer.render(stage);
* });
*
* @example
* // Or you can just update it manually.
* ticker.autoStart = false;
* ticker.stop();
* function animate(time) {
* ticker.update(time);
* renderer.render(stage);
* requestAnimationFrame(animate);
* }
* animate(performance.now());
*
* @member {PIXI.Ticker}
* @static
*/
staticAccessors.shared.get = function ()
{
if (!Ticker._shared)
{
var shared = Ticker._shared = new Ticker();
shared.autoStart = true;
shared._protected = true;
}
return Ticker._shared;
};
/**
* The system ticker instance used by {@link PIXI.interaction.InteractionManager} and by
* {@link PIXI.BasePrepare} for core timing functionality that shouldn't usually need to be paused,
* unlike the `shared` ticker which drives visual animations and rendering which may want to be paused.
*
* The property {@link PIXI.Ticker#autoStart} is set to `true` for this instance.
*
* @member {PIXI.Ticker}
* @static
*/
staticAccessors.system.get = function ()
{
if (!Ticker._system)
{
var system = Ticker._system = new Ticker();
system.autoStart = true;
system._protected = true;
}
return Ticker._system;
};
Object.defineProperties( Ticker.prototype, prototypeAccessors );
Object.defineProperties( Ticker, staticAccessors );
/**
* Middleware for for Application Ticker.

@@ -865,100 +742,91 @@ *

*/
var TickerPlugin = function TickerPlugin () {};
TickerPlugin.init = function init (options)
{
var this$1 = this;
// Set default
options = Object.assign({
autoStart: true,
sharedTicker: false,
}, options);
// Create ticker setter
Object.defineProperty(this, 'ticker',
{
set: function set(ticker)
{
if (this._ticker)
{
var TickerPlugin = /** @class */ (function () {
function TickerPlugin() {
}
/**
* Initialize the plugin with scope of application instance
*
* @static
* @private
* @param {object} [options] - See application options
*/
TickerPlugin.init = function (options) {
var _this = this;
// Set default
options = Object.assign({
autoStart: true,
sharedTicker: false,
}, options);
// Create ticker setter
Object.defineProperty(this, 'ticker', {
set: function (ticker) {
if (this._ticker) {
this._ticker.remove(this.render, this);
}
this._ticker = ticker;
if (ticker)
{
ticker.add(this.render, this, UPDATE_PRIORITY.LOW);
if (ticker) {
ticker.add(this.render, this, exports.UPDATE_PRIORITY.LOW);
}
},
get: function get()
{
get: function () {
return this._ticker;
},
});
/**
* Convenience method for stopping the render.
*
* @method PIXI.Application#stop
*/
this.stop = function () {
this$1._ticker.stop();
/**
* Convenience method for stopping the render.
*
* @method PIXI.Application#stop
*/
this.stop = function () {
_this._ticker.stop();
};
/**
* Convenience method for starting the render.
*
* @method PIXI.Application#start
*/
this.start = function () {
_this._ticker.start();
};
/**
* Internal reference to the ticker.
*
* @type {PIXI.Ticker}
* @name _ticker
* @memberof PIXI.Application#
* @private
*/
this._ticker = null;
/**
* Ticker for doing render updates.
*
* @type {PIXI.Ticker}
* @name ticker
* @memberof PIXI.Application#
* @default PIXI.Ticker.shared
*/
this.ticker = options.sharedTicker ? Ticker.shared : new Ticker();
// Start the rendering
if (options.autoStart) {
this.start();
}
};
/**
* Convenience method for starting the render.
* Clean up the ticker, scoped to application.
*
* @method PIXI.Application#start
* @static
* @private
*/
this.start = function () {
this$1._ticker.start();
TickerPlugin.destroy = function () {
if (this._ticker) {
var oldTicker = this._ticker;
this.ticker = null;
oldTicker.destroy();
}
};
return TickerPlugin;
}());
/**
* Internal reference to the ticker.
*
* @type {PIXI.Ticker}
* @name _ticker
* @memberof PIXI.Application#
* @private
*/
this._ticker = null;
/**
* Ticker for doing render updates.
*
* @type {PIXI.Ticker}
* @name ticker
* @memberof PIXI.Application#
* @default PIXI.Ticker.shared
*/
this.ticker = options.sharedTicker ? Ticker.shared : new Ticker();
// Start the rendering
if (options.autoStart)
{
this.start();
}
};
/**
* Clean up the ticker, scoped to application.
*
* @static
* @private
*/
TickerPlugin.destroy = function destroy ()
{
if (this._ticker)
{
var oldTicker = this._ticker;
this.ticker = null;
oldTicker.destroy();
}
};
exports.Ticker = Ticker;
exports.TickerPlugin = TickerPlugin;
exports.UPDATE_PRIORITY = UPDATE_PRIORITY;

@@ -965,0 +833,0 @@ return exports;

/*!
* @pixi/ticker - v5.1.3
* Compiled Mon, 09 Sep 2019 04:51:53 UTC
* @pixi/ticker - v5.2.0
* Compiled Wed, 06 Nov 2019 02:32:43 UTC
*

@@ -8,3 +8,3 @@ * @pixi/ticker is licensed under the MIT License.

*/
this.PIXI=this.PIXI||{};var _pixi_ticker=function(t,e){"use strict";e.settings.TARGET_FPMS=.06;var i={INTERACTION:50,HIGH:25,NORMAL:0,LOW:-25,UTILITY:-50},s=function(t,e,i,s){void 0===e&&(e=null),void 0===i&&(i=0),void 0===s&&(s=!1),this.fn=t,this.context=e,this.priority=i,this.once=s,this.next=null,this.previous=null,this._destroyed=!1};s.prototype.match=function(t,e){return e=e||null,this.fn===t&&this.context===e},s.prototype.emit=function(t){this.fn&&(this.context?this.fn.call(this.context,t):this.fn(t));var e=this.next;return this.once&&this.destroy(!0),this._destroyed&&(this.next=null),e},s.prototype.connect=function(t){this.previous=t,t.next&&(t.next.previous=this),this.next=t.next,t.next=this},s.prototype.destroy=function(t){void 0===t&&(t=!1),this._destroyed=!0,this.fn=null,this.context=null,this.previous&&(this.previous.next=this.next),this.next&&(this.next.previous=this.previous);var e=this.next;return this.next=t?null:e,this.previous=null,e};var n=function(){var t=this;this._head=new s(null,null,1/0),this._requestId=null,this._maxElapsedMS=100,this._minElapsedMS=0,this.autoStart=!1,this.deltaTime=1,this.deltaMS=1/e.settings.TARGET_FPMS,this.elapsedMS=1/e.settings.TARGET_FPMS,this.lastTime=-1,this.speed=1,this.started=!1,this._protected=!1,this._lastFrame=-1,this._tick=function(e){t._requestId=null,t.started&&(t.update(e),t.started&&null===t._requestId&&t._head.next&&(t._requestId=requestAnimationFrame(t._tick)))}},r={FPS:{configurable:!0},minFPS:{configurable:!0},maxFPS:{configurable:!0}},h={shared:{configurable:!0},system:{configurable:!0}};n.prototype._requestIfNeeded=function(){null===this._requestId&&this._head.next&&(this.lastTime=performance.now(),this._lastFrame=this.lastTime,this._requestId=requestAnimationFrame(this._tick))},n.prototype._cancelIfNeeded=function(){null!==this._requestId&&(cancelAnimationFrame(this._requestId),this._requestId=null)},n.prototype._startIfPossible=function(){this.started?this._requestIfNeeded():this.autoStart&&this.start()},n.prototype.add=function(t,e,n){return void 0===n&&(n=i.NORMAL),this._addListener(new s(t,e,n))},n.prototype.addOnce=function(t,e,n){return void 0===n&&(n=i.NORMAL),this._addListener(new s(t,e,n,!0))},n.prototype._addListener=function(t){var e=this._head.next,i=this._head;if(e){for(;e;){if(t.priority>e.priority){t.connect(i);break}i=e,e=e.next}t.previous||t.connect(i)}else t.connect(i);return this._startIfPossible(),this},n.prototype.remove=function(t,e){for(var i=this._head.next;i;)i=i.match(t,e)?i.destroy():i.next;return this._head.next||this._cancelIfNeeded(),this},n.prototype.start=function(){this.started||(this.started=!0,this._requestIfNeeded())},n.prototype.stop=function(){this.started&&(this.started=!1,this._cancelIfNeeded())},n.prototype.destroy=function(){if(!this._protected){this.stop();for(var t=this._head.next;t;)t=t.destroy(!0);this._head.destroy(),this._head=null}},n.prototype.update=function(t){var i;if(void 0===t&&(t=performance.now()),t>this.lastTime){if((i=this.elapsedMS=t-this.lastTime)>this._maxElapsedMS&&(i=this._maxElapsedMS),i*=this.speed,this._minElapsedMS){var s=t-this._lastFrame|0;if(s<this._minElapsedMS)return;this._lastFrame=t-s%this._minElapsedMS}this.deltaMS=i,this.deltaTime=this.deltaMS*e.settings.TARGET_FPMS;for(var n=this._head,r=n.next;r;)r=r.emit(this.deltaTime);n.next||this._cancelIfNeeded()}else this.deltaTime=this.deltaMS=this.elapsedMS=0;this.lastTime=t},r.FPS.get=function(){return 1e3/this.elapsedMS},r.minFPS.get=function(){return 1e3/this._maxElapsedMS},r.minFPS.set=function(t){var i=Math.min(this.maxFPS,t),s=Math.min(Math.max(0,i)/1e3,e.settings.TARGET_FPMS);this._maxElapsedMS=1/s},r.maxFPS.get=function(){return this._minElapsedMS?Math.round(1e3/this._minElapsedMS):0},r.maxFPS.set=function(t){if(0===t)this._minElapsedMS=0;else{var e=Math.max(this.minFPS,t);this._minElapsedMS=1/(e/1e3)}},h.shared.get=function(){if(!n._shared){var t=n._shared=new n;t.autoStart=!0,t._protected=!0}return n._shared},h.system.get=function(){if(!n._system){var t=n._system=new n;t.autoStart=!0,t._protected=!0}return n._system},Object.defineProperties(n.prototype,r),Object.defineProperties(n,h);var a=function(){};return a.init=function(t){var e=this;t=Object.assign({autoStart:!0,sharedTicker:!1},t),Object.defineProperty(this,"ticker",{set:function(t){this._ticker&&this._ticker.remove(this.render,this),this._ticker=t,t&&t.add(this.render,this,i.LOW)},get:function(){return this._ticker}}),this.stop=function(){e._ticker.stop()},this.start=function(){e._ticker.start()},this._ticker=null,this.ticker=t.sharedTicker?n.shared:new n,t.autoStart&&this.start()},a.destroy=function(){if(this._ticker){var t=this._ticker;this.ticker=null,t.destroy()}},t.Ticker=n,t.TickerPlugin=a,t.UPDATE_PRIORITY=i,t}({},PIXI);Object.assign(this.PIXI,_pixi_ticker);
this.PIXI=this.PIXI||{};var _pixi_ticker=function(t,e){"use strict";var i;e.settings.TARGET_FPMS=.06,(i=t.UPDATE_PRIORITY||(t.UPDATE_PRIORITY={}))[i.INTERACTION=50]="INTERACTION",i[i.HIGH=25]="HIGH",i[i.NORMAL=0]="NORMAL",i[i.LOW=-25]="LOW",i[i.UTILITY=-50]="UTILITY";var s=function(){function t(t,e,i,s){void 0===e&&(e=null),void 0===i&&(i=0),void 0===s&&(s=!1),this.fn=t,this.context=e,this.priority=i,this.once=s,this.next=null,this.previous=null,this._destroyed=!1}return t.prototype.match=function(t,e){return void 0===e&&(e=null),this.fn===t&&this.context===e},t.prototype.emit=function(t){this.fn&&(this.context?this.fn.call(this.context,t):this.fn(t));var e=this.next;return this.once&&this.destroy(!0),this._destroyed&&(this.next=null),e},t.prototype.connect=function(t){this.previous=t,t.next&&(t.next.previous=this),this.next=t.next,t.next=this},t.prototype.destroy=function(t){void 0===t&&(t=!1),this._destroyed=!0,this.fn=null,this.context=null,this.previous&&(this.previous.next=this.next),this.next&&(this.next.previous=this.previous);var e=this.next;return this.next=t?null:e,this.previous=null,e},t}(),n=function(){function i(){var t=this;this._head=new s(null,null,1/0),this._requestId=null,this._maxElapsedMS=100,this._minElapsedMS=0,this.autoStart=!1,this.deltaTime=1,this.deltaMS=1/e.settings.TARGET_FPMS,this.elapsedMS=1/e.settings.TARGET_FPMS,this.lastTime=-1,this.speed=1,this.started=!1,this._protected=!1,this._lastFrame=-1,this._tick=function(e){t._requestId=null,t.started&&(t.update(e),t.started&&null===t._requestId&&t._head.next&&(t._requestId=requestAnimationFrame(t._tick)))}}return i.prototype._requestIfNeeded=function(){null===this._requestId&&this._head.next&&(this.lastTime=performance.now(),this._lastFrame=this.lastTime,this._requestId=requestAnimationFrame(this._tick))},i.prototype._cancelIfNeeded=function(){null!==this._requestId&&(cancelAnimationFrame(this._requestId),this._requestId=null)},i.prototype._startIfPossible=function(){this.started?this._requestIfNeeded():this.autoStart&&this.start()},i.prototype.add=function(e,i,n){return void 0===n&&(n=t.UPDATE_PRIORITY.NORMAL),this._addListener(new s(e,i,n))},i.prototype.addOnce=function(e,i,n){return void 0===n&&(n=t.UPDATE_PRIORITY.NORMAL),this._addListener(new s(e,i,n,!0))},i.prototype._addListener=function(t){var e=this._head.next,i=this._head;if(e){for(;e;){if(t.priority>e.priority){t.connect(i);break}i=e,e=e.next}t.previous||t.connect(i)}else t.connect(i);return this._startIfPossible(),this},i.prototype.remove=function(t,e){for(var i=this._head.next;i;)i=i.match(t,e)?i.destroy():i.next;return this._head.next||this._cancelIfNeeded(),this},i.prototype.start=function(){this.started||(this.started=!0,this._requestIfNeeded())},i.prototype.stop=function(){this.started&&(this.started=!1,this._cancelIfNeeded())},i.prototype.destroy=function(){if(!this._protected){this.stop();for(var t=this._head.next;t;)t=t.destroy(!0);this._head.destroy(),this._head=null}},i.prototype.update=function(t){var i;if(void 0===t&&(t=performance.now()),t>this.lastTime){if((i=this.elapsedMS=t-this.lastTime)>this._maxElapsedMS&&(i=this._maxElapsedMS),i*=this.speed,this._minElapsedMS){var s=t-this._lastFrame|0;if(s<this._minElapsedMS)return;this._lastFrame=t-s%this._minElapsedMS}this.deltaMS=i,this.deltaTime=this.deltaMS*e.settings.TARGET_FPMS;for(var n=this._head,r=n.next;r;)r=r.emit(this.deltaTime);n.next||this._cancelIfNeeded()}else this.deltaTime=this.deltaMS=this.elapsedMS=0;this.lastTime=t},Object.defineProperty(i.prototype,"FPS",{get:function(){return 1e3/this.elapsedMS},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"minFPS",{get:function(){return 1e3/this._maxElapsedMS},set:function(t){var i=Math.min(this.maxFPS,t),s=Math.min(Math.max(0,i)/1e3,e.settings.TARGET_FPMS);this._maxElapsedMS=1/s},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"maxFPS",{get:function(){return this._minElapsedMS?Math.round(1e3/this._minElapsedMS):0},set:function(t){if(0===t)this._minElapsedMS=0;else{var e=Math.max(this.minFPS,t);this._minElapsedMS=1/(e/1e3)}},enumerable:!0,configurable:!0}),Object.defineProperty(i,"shared",{get:function(){if(!i._shared){var t=i._shared=new i;t.autoStart=!0,t._protected=!0}return i._shared},enumerable:!0,configurable:!0}),Object.defineProperty(i,"system",{get:function(){if(!i._system){var t=i._system=new i;t.autoStart=!0,t._protected=!0}return i._system},enumerable:!0,configurable:!0}),i}(),r=function(){function e(){}return e.init=function(e){var i=this;e=Object.assign({autoStart:!0,sharedTicker:!1},e),Object.defineProperty(this,"ticker",{set:function(e){this._ticker&&this._ticker.remove(this.render,this),this._ticker=e,e&&e.add(this.render,this,t.UPDATE_PRIORITY.LOW)},get:function(){return this._ticker}}),this.stop=function(){i._ticker.stop()},this.start=function(){i._ticker.start()},this._ticker=null,this.ticker=e.sharedTicker?n.shared:new n,e.autoStart&&this.start()},e.destroy=function(){if(this._ticker){var t=this._ticker;this.ticker=null,t.destroy()}},e}();return t.Ticker=n,t.TickerPlugin=r,t}({},PIXI);Object.assign(this.PIXI,_pixi_ticker);
//# sourceMappingURL=ticker.min.js.map
/*!
* @pixi/ticker - v5.1.3
* Compiled Mon, 09 Sep 2019 04:51:53 UTC
* @pixi/ticker - v5.2.0
* Compiled Wed, 06 Nov 2019 02:32:43 UTC
*

@@ -30,3 +30,3 @@ * @pixi/ticker is licensed under the MIT License.

* @memberof PIXI
* @type {object}
* @enum {number}
* @property {number} INTERACTION=50 Highest priority, used for {@link PIXI.interaction.InteractionManager}

@@ -38,9 +38,10 @@ * @property {number} HIGH=25 High priority updating, {@link PIXI.VideoBaseTexture} and {@link PIXI.AnimatedSprite}

*/
var UPDATE_PRIORITY = {
INTERACTION: 50,
HIGH: 25,
NORMAL: 0,
LOW: -25,
UTILITY: -50,
};
var UPDATE_PRIORITY;
(function (UPDATE_PRIORITY) {
UPDATE_PRIORITY[UPDATE_PRIORITY["INTERACTION"] = 50] = "INTERACTION";
UPDATE_PRIORITY[UPDATE_PRIORITY["HIGH"] = 25] = "HIGH";
UPDATE_PRIORITY[UPDATE_PRIORITY["NORMAL"] = 0] = "NORMAL";
UPDATE_PRIORITY[UPDATE_PRIORITY["LOW"] = -25] = "LOW";
UPDATE_PRIORITY[UPDATE_PRIORITY["UTILITY"] = -50] = "UTILITY";
})(UPDATE_PRIORITY || (UPDATE_PRIORITY = {}));

@@ -54,162 +55,138 @@ /**

*/
var TickerListener = function TickerListener(fn, context, priority, once)
{
if ( context === void 0 ) context = null;
if ( priority === void 0 ) priority = 0;
if ( once === void 0 ) once = false;
var TickerListener = /** @class */ (function () {
/**
* The handler function to execute.
* Constructor
* @private
* @member {Function}
* @param {Function} fn - The listener function to be added for one update
* @param {*} [context=null] - The listener context
* @param {number} [priority=0] - The priority for emitting
* @param {boolean} [once=false] - If the handler should fire once
*/
this.fn = fn;
function TickerListener(fn, context, priority, once) {
if (context === void 0) { context = null; }
if (priority === void 0) { priority = 0; }
if (once === void 0) { once = false; }
/**
* The handler function to execute.
* @private
* @member {Function}
*/
this.fn = fn;
/**
* The calling to execute.
* @private
* @member {*}
*/
this.context = context;
/**
* The current priority.
* @private
* @member {number}
*/
this.priority = priority;
/**
* If this should only execute once.
* @private
* @member {boolean}
*/
this.once = once;
/**
* The next item in chain.
* @private
* @member {TickerListener}
*/
this.next = null;
/**
* The previous item in chain.
* @private
* @member {TickerListener}
*/
this.previous = null;
/**
* `true` if this listener has been destroyed already.
* @member {boolean}
* @private
*/
this._destroyed = false;
}
/**
* The calling to execute.
* Simple compare function to figure out if a function and context match.
* @private
* @member {*}
* @param {Function} fn - The listener function to be added for one update
* @param {any} [context] - The listener context
* @return {boolean} `true` if the listener match the arguments
*/
this.context = context;
TickerListener.prototype.match = function (fn, context) {
if (context === void 0) { context = null; }
return this.fn === fn && this.context === context;
};
/**
* The current priority.
* Emit by calling the current function.
* @private
* @member {number}
* @param {number} deltaTime - time since the last emit.
* @return {TickerListener} Next ticker
*/
this.priority = priority;
TickerListener.prototype.emit = function (deltaTime) {
if (this.fn) {
if (this.context) {
this.fn.call(this.context, deltaTime);
}
else {
this.fn(deltaTime);
}
}
var redirect = this.next;
if (this.once) {
this.destroy(true);
}
// Soft-destroying should remove
// the next reference
if (this._destroyed) {
this.next = null;
}
return redirect;
};
/**
* If this should only execute once.
* Connect to the list.
* @private
* @member {boolean}
* @param {TickerListener} previous - Input node, previous listener
*/
this.once = once;
TickerListener.prototype.connect = function (previous) {
this.previous = previous;
if (previous.next) {
previous.next.previous = this;
}
this.next = previous.next;
previous.next = this;
};
/**
* The next item in chain.
* Destroy and don't use after this.
* @private
* @member {TickerListener}
* @param {boolean} [hard = false] `true` to remove the `next` reference, this
* is considered a hard destroy. Soft destroy maintains the next reference.
* @return {TickerListener} The listener to redirect while emitting or removing.
*/
this.next = null;
/**
* The previous item in chain.
* @private
* @member {TickerListener}
*/
this.previous = null;
/**
* `true` if this listener has been destroyed already.
* @member {boolean}
* @private
*/
this._destroyed = false;
};
/**
* Simple compare function to figure out if a function and context match.
* @private
* @param {Function} fn - The listener function to be added for one update
* @param {Function} context - The listener context
* @return {boolean} `true` if the listener match the arguments
*/
TickerListener.prototype.match = function match (fn, context)
{
context = context || null;
return this.fn === fn && this.context === context;
};
/**
* Emit by calling the current function.
* @private
* @param {number} deltaTime - time since the last emit.
* @return {TickerListener} Next ticker
*/
TickerListener.prototype.emit = function emit (deltaTime)
{
if (this.fn)
{
if (this.context)
{
this.fn.call(this.context, deltaTime);
TickerListener.prototype.destroy = function (hard) {
if (hard === void 0) { hard = false; }
this._destroyed = true;
this.fn = null;
this.context = null;
// Disconnect, hook up next and previous
if (this.previous) {
this.previous.next = this.next;
}
else
{
this.fn(deltaTime);
if (this.next) {
this.next.previous = this.previous;
}
}
// Redirect to the next item
var redirect = this.next;
// Remove references
this.next = hard ? null : redirect;
this.previous = null;
return redirect;
};
return TickerListener;
}());
var redirect = this.next;
if (this.once)
{
this.destroy(true);
}
// Soft-destroying should remove
// the next reference
if (this._destroyed)
{
this.next = null;
}
return redirect;
};
/**
* Connect to the list.
* @private
* @param {TickerListener} previous - Input node, previous listener
*/
TickerListener.prototype.connect = function connect (previous)
{
this.previous = previous;
if (previous.next)
{
previous.next.previous = this;
}
this.next = previous.next;
previous.next = this;
};
/**
* Destroy and don't use after this.
* @private
* @param {boolean} [hard = false] `true` to remove the `next` reference, this
* is considered a hard destroy. Soft destroy maintains the next reference.
* @return {TickerListener} The listener to redirect while emitting or removing.
*/
TickerListener.prototype.destroy = function destroy (hard)
{
if ( hard === void 0 ) hard = false;
this._destroyed = true;
this.fn = null;
this.context = null;
// Disconnect, hook up next and previous
if (this.previous)
{
this.previous.next = this.next;
}
if (this.next)
{
this.next.previous = this.previous;
}
// Redirect to the next item
var redirect = this.next;
// Remove references
this.next = hard ? null : redirect;
this.previous = null;
return redirect;
};
/**
* A Ticker class that runs an update loop that other objects listen to.

@@ -223,631 +200,532 @@ *

*/
var Ticker = function Ticker()
{
var this$1 = this;
var Ticker = /** @class */ (function () {
function Ticker() {
var _this = this;
/**
* The first listener. All new listeners added are chained on this.
* @private
* @type {TickerListener}
*/
this._head = new TickerListener(null, null, Infinity);
/**
* Internal current frame request ID
* @type {?number}
* @private
*/
this._requestId = null;
/**
* Internal value managed by minFPS property setter and getter.
* This is the maximum allowed milliseconds between updates.
* @type {number}
* @private
*/
this._maxElapsedMS = 100;
/**
* Internal value managed by maxFPS property setter and getter.
* This is the minimum allowed milliseconds between updates.
* @type {number}
* @private
*/
this._minElapsedMS = 0;
/**
* Whether or not this ticker should invoke the method
* {@link PIXI.Ticker#start} automatically
* when a listener is added.
*
* @member {boolean}
* @default false
*/
this.autoStart = false;
/**
* Scalar time value from last frame to this frame.
* This value is capped by setting {@link PIXI.Ticker#minFPS}
* and is scaled with {@link PIXI.Ticker#speed}.
* **Note:** The cap may be exceeded by scaling.
*
* @member {number}
* @default 1
*/
this.deltaTime = 1;
/**
* Scaler time elapsed in milliseconds from last frame to this frame.
* This value is capped by setting {@link PIXI.Ticker#minFPS}
* and is scaled with {@link PIXI.Ticker#speed}.
* **Note:** The cap may be exceeded by scaling.
* If the platform supports DOMHighResTimeStamp,
* this value will have a precision of 1 µs.
* Defaults to target frame time
*
* @member {number}
* @default 16.66
*/
this.deltaMS = 1 / settings.TARGET_FPMS;
/**
* Time elapsed in milliseconds from last frame to this frame.
* Opposed to what the scalar {@link PIXI.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
*
* @member {number}
* @default 16.66
*/
this.elapsedMS = 1 / settings.TARGET_FPMS;
/**
* The last time {@link PIXI.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.
*
* @member {number}
* @default -1
*/
this.lastTime = -1;
/**
* Factor of current {@link PIXI.Ticker#deltaTime}.
* @example
* // Scales ticker.deltaTime to what would be
* // the equivalent of approximately 120 FPS
* ticker.speed = 2;
*
* @member {number}
* @default 1
*/
this.speed = 1;
/**
* Whether or not this ticker has been started.
* `true` if {@link PIXI.Ticker#start} has been called.
* `false` if {@link PIXI.Ticker#stop} has been called.
* While `false`, this value may change to `true` in the
* event of {@link PIXI.Ticker#autoStart} being `true`
* and a listener is added.
*
* @member {boolean}
* @default false
*/
this.started = false;
/**
* If enabled, deleting is disabled.
* @member {boolean}
* @default false
* @private
*/
this._protected = false;
/**
* The last time keyframe was executed.
* Maintains a relatively fixed interval with the previous value.
* @member {number}
* @default -1
* @private
*/
this._lastFrame = -1;
/**
* Internal tick method bound to ticker instance.
* This is because in early 2015, Function.bind
* is still 60% slower in high performance scenarios.
* Also separating frame requests from update method
* so listeners may be called at any time and with
* any animation API, just invoke ticker.update(time).
*
* @private
* @param {number} time - Time since last tick.
*/
this._tick = function (time) {
_this._requestId = null;
if (_this.started) {
// Invoke listeners now
_this.update(time);
// Listener side effects may have modified ticker state.
if (_this.started && _this._requestId === null && _this._head.next) {
_this._requestId = requestAnimationFrame(_this._tick);
}
}
};
}
/**
* The first listener. All new listeners added are chained on this.
* Conditionally requests a new animation frame.
* If a frame has not already been requested, and if the internal
* emitter has listeners, a new frame is requested.
*
* @private
* @type {TickerListener}
*/
this._head = new TickerListener(null, null, Infinity);
Ticker.prototype._requestIfNeeded = function () {
if (this._requestId === null && this._head.next) {
// ensure callbacks get correct delta
this.lastTime = performance.now();
this._lastFrame = this.lastTime;
this._requestId = requestAnimationFrame(this._tick);
}
};
/**
* Internal current frame request ID
* @type {?number}
* Conditionally cancels a pending animation frame.
*
* @private
*/
this._requestId = null;
Ticker.prototype._cancelIfNeeded = function () {
if (this._requestId !== null) {
cancelAnimationFrame(this._requestId);
this._requestId = null;
}
};
/**
* Internal value managed by minFPS property setter and getter.
* This is the maximum allowed milliseconds between updates.
* @type {number}
* Conditionally requests a new animation frame.
* If the ticker has been started it checks if a frame has not already
* been requested, and if the internal emitter has listeners. If these
* conditions are met, a new frame is requested. If the ticker has not
* been started, but autoStart is `true`, then the ticker starts now,
* and continues with the previous conditions to request a new frame.
*
* @private
*/
this._maxElapsedMS = 100;
Ticker.prototype._startIfPossible = function () {
if (this.started) {
this._requestIfNeeded();
}
else if (this.autoStart) {
this.start();
}
};
/**
* Internal value managed by maxFPS property setter and getter.
* This is the minimum allowed milliseconds between updates.
* @private
*/
this._minElapsedMS = 0;
/**
* Whether or not this ticker should invoke the method
* {@link PIXI.Ticker#start} automatically
* when a listener is added.
* Register a handler for tick events. Calls continuously unless
* it is removed or the ticker is stopped.
*
* @member {boolean}
* @default false
* @param {Function} fn - The listener function to be added for updates
* @param {*} [context] - The listener context
* @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting
* @returns {PIXI.Ticker} This instance of a ticker
*/
this.autoStart = false;
Ticker.prototype.add = function (fn, context, priority) {
if (priority === void 0) { priority = UPDATE_PRIORITY.NORMAL; }
return this._addListener(new TickerListener(fn, context, priority));
};
/**
* Scalar time value from last frame to this frame.
* This value is capped by setting {@link PIXI.Ticker#minFPS}
* and is scaled with {@link PIXI.Ticker#speed}.
* **Note:** The cap may be exceeded by scaling.
* Add a handler for the tick event which is only execute once.
*
* @member {number}
* @default 1
* @param {Function} fn - The listener function to be added for one update
* @param {*} [context] - The listener context
* @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting
* @returns {PIXI.Ticker} This instance of a ticker
*/
this.deltaTime = 1;
Ticker.prototype.addOnce = function (fn, context, priority) {
if (priority === void 0) { priority = UPDATE_PRIORITY.NORMAL; }
return this._addListener(new TickerListener(fn, context, priority, true));
};
/**
* Scaler time elapsed in milliseconds from last frame to this frame.
* This value is capped by setting {@link PIXI.Ticker#minFPS}
* and is scaled with {@link PIXI.Ticker#speed}.
* **Note:** The cap may be exceeded by scaling.
* If the platform supports DOMHighResTimeStamp,
* this value will have a precision of 1 µs.
* Defaults to target frame time
* Internally adds the event handler so that it can be sorted by priority.
* Priority allows certain handler (user, AnimatedSprite, Interaction) to be run
* before the rendering.
*
* @member {number}
* @default 16.66
* @private
* @param {TickerListener} listener - Current listener being added.
* @returns {PIXI.Ticker} This instance of a ticker
*/
this.deltaMS = 1 / settings.TARGET_FPMS;
Ticker.prototype._addListener = function (listener) {
// For attaching to head
var current = this._head.next;
var previous = this._head;
// Add the first item
if (!current) {
listener.connect(previous);
}
else {
// Go from highest to lowest priority
while (current) {
if (listener.priority > current.priority) {
listener.connect(previous);
break;
}
previous = current;
current = current.next;
}
// Not yet connected
if (!listener.previous) {
listener.connect(previous);
}
}
this._startIfPossible();
return this;
};
/**
* Time elapsed in milliseconds from last frame to this frame.
* Opposed to what the scalar {@link PIXI.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
* Removes any handlers matching the function and context parameters.
* If no handlers are left after removing, then it cancels the animation frame.
*
* @member {number}
* @default 16.66
* @param {Function} fn - The listener function to be removed
* @param {*} [context] - The listener context to be removed
* @returns {PIXI.Ticker} This instance of a ticker
*/
this.elapsedMS = 1 / settings.TARGET_FPMS;
Ticker.prototype.remove = function (fn, context) {
var listener = this._head.next;
while (listener) {
// We found a match, lets remove it
// no break to delete all possible matches
// incase a listener was added 2+ times
if (listener.match(fn, context)) {
listener = listener.destroy();
}
else {
listener = listener.next;
}
}
if (!this._head.next) {
this._cancelIfNeeded();
}
return this;
};
/**
* The last time {@link PIXI.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.
*
* @member {number}
* @default -1
* Starts the ticker. If the ticker has listeners
* a new animation frame is requested at this point.
*/
this.lastTime = -1;
Ticker.prototype.start = function () {
if (!this.started) {
this.started = true;
this._requestIfNeeded();
}
};
/**
* Factor of current {@link PIXI.Ticker#deltaTime}.
* @example
* // Scales ticker.deltaTime to what would be
* // the equivalent of approximately 120 FPS
* ticker.speed = 2;
*
* @member {number}
* @default 1
* Stops the ticker. If the ticker has requested
* an animation frame it is canceled at this point.
*/
this.speed = 1;
Ticker.prototype.stop = function () {
if (this.started) {
this.started = false;
this._cancelIfNeeded();
}
};
/**
* Whether or not this ticker has been started.
* `true` if {@link PIXI.Ticker#start} has been called.
* `false` if {@link PIXI.Ticker#stop} has been called.
* While `false`, this value may change to `true` in the
* event of {@link PIXI.Ticker#autoStart} being `true`
* and a listener is added.
*
* @member {boolean}
* @default false
* Destroy the ticker and don't use after this. Calling
* this method removes all references to internal events.
*/
this.started = false;
Ticker.prototype.destroy = function () {
if (!this._protected) {
this.stop();
var listener = this._head.next;
while (listener) {
listener = listener.destroy(true);
}
this._head.destroy();
this._head = null;
}
};
/**
* If enabled, deleting is disabled.
* @member {boolean}
* @default false
* @private
*/
this._protected = false;
/**
* The last time keyframe was executed.
* Maintains a relatively fixed interval with the previous value.
* @member {number}
* @default -1
* @private
*/
this._lastFrame = -1;
/**
* Internal tick method bound to ticker instance.
* This is because in early 2015, Function.bind
* is still 60% slower in high performance scenarios.
* Also separating frame requests from update method
* so listeners may be called at any time and with
* any animation API, just invoke ticker.update(time).
* Triggers an update. An update entails setting the
* current {@link PIXI.Ticker#elapsedMS},
* the current {@link PIXI.Ticker#deltaTime},
* invoking all listeners with current deltaTime,
* and then finally setting {@link PIXI.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.
*
* @private
* @param {number} time - Time since last tick.
* @param {number} [currentTime=performance.now()] - the current time of execution
*/
this._tick = function (time) {
this$1._requestId = null;
if (this$1.started)
{
// Invoke listeners now
this$1.update(time);
// Listener side effects may have modified ticker state.
if (this$1.started && this$1._requestId === null && this$1._head.next)
{
this$1._requestId = requestAnimationFrame(this$1._tick);
Ticker.prototype.update = function (currentTime) {
if (currentTime === void 0) { currentTime = performance.now(); }
var elapsedMS;
// If the difference in time is zero or negative, we ignore most of the work done here.
// If there is no valid difference, then should be no reason to let anyone know about it.
// A zero delta, is exactly that, nothing should update.
//
// The difference in time can be negative, and no this does not mean time traveling.
// This can be the result of a race condition between when an animation frame is requested
// on the current JavaScript engine event loop, and when the ticker's start method is invoked
// (which invokes the internal _requestIfNeeded method). If a frame is requested before
// _requestIfNeeded is invoked, then the callback for the animation frame the ticker requests,
// can receive a time argument that can be less than the lastTime value that was set within
// _requestIfNeeded. This difference is in microseconds, but this is enough to cause problems.
//
// This check covers this browser engine timing issue, as well as if consumers pass an invalid
// currentTime value. This may happen if consumers opt-out of the autoStart, and update themselves.
if (currentTime > this.lastTime) {
// Save uncapped elapsedMS for measurement
elapsedMS = this.elapsedMS = currentTime - this.lastTime;
// cap the milliseconds elapsed used for deltaTime
if (elapsedMS > this._maxElapsedMS) {
elapsedMS = this._maxElapsedMS;
}
}
};
};
var prototypeAccessors = { FPS: { configurable: true },minFPS: { configurable: true },maxFPS: { configurable: true } };
var staticAccessors = { shared: { configurable: true },system: { configurable: true } };
/**
* Conditionally requests a new animation frame.
* If a frame has not already been requested, and if the internal
* emitter has listeners, a new frame is requested.
*
* @private
*/
Ticker.prototype._requestIfNeeded = function _requestIfNeeded ()
{
if (this._requestId === null && this._head.next)
{
// ensure callbacks get correct delta
this.lastTime = performance.now();
this._lastFrame = this.lastTime;
this._requestId = requestAnimationFrame(this._tick);
}
};
/**
* Conditionally cancels a pending animation frame.
*
* @private
*/
Ticker.prototype._cancelIfNeeded = function _cancelIfNeeded ()
{
if (this._requestId !== null)
{
cancelAnimationFrame(this._requestId);
this._requestId = null;
}
};
/**
* Conditionally requests a new animation frame.
* If the ticker has been started it checks if a frame has not already
* been requested, and if the internal emitter has listeners. If these
* conditions are met, a new frame is requested. If the ticker has not
* been started, but autoStart is `true`, then the ticker starts now,
* and continues with the previous conditions to request a new frame.
*
* @private
*/
Ticker.prototype._startIfPossible = function _startIfPossible ()
{
if (this.started)
{
this._requestIfNeeded();
}
else if (this.autoStart)
{
this.start();
}
};
/**
* Register a handler for tick events. Calls continuously unless
* it is removed or the ticker is stopped.
*
* @param {Function} fn - The listener function to be added for updates
* @param {*} [context] - The listener context
* @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting
* @returns {PIXI.Ticker} This instance of a ticker
*/
Ticker.prototype.add = function add (fn, context, priority)
{
if ( priority === void 0 ) priority = UPDATE_PRIORITY.NORMAL;
return this._addListener(new TickerListener(fn, context, priority));
};
/**
* Add a handler for the tick event which is only execute once.
*
* @param {Function} fn - The listener function to be added for one update
* @param {*} [context] - The listener context
* @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting
* @returns {PIXI.Ticker} This instance of a ticker
*/
Ticker.prototype.addOnce = function addOnce (fn, context, priority)
{
if ( priority === void 0 ) priority = UPDATE_PRIORITY.NORMAL;
return this._addListener(new TickerListener(fn, context, priority, true));
};
/**
* Internally adds the event handler so that it can be sorted by priority.
* Priority allows certain handler (user, AnimatedSprite, Interaction) to be run
* before the rendering.
*
* @private
* @param {TickerListener} listener - Current listener being added.
* @returns {PIXI.Ticker} This instance of a ticker
*/
Ticker.prototype._addListener = function _addListener (listener)
{
// For attaching to head
var current = this._head.next;
var previous = this._head;
// Add the first item
if (!current)
{
listener.connect(previous);
}
else
{
// Go from highest to lowest priority
while (current)
{
if (listener.priority > current.priority)
{
listener.connect(previous);
break;
elapsedMS *= this.speed;
// If not enough time has passed, exit the function.
// Get ready for next frame by setting _lastFrame, but based on _minElapsedMS
// adjustment to ensure a relatively stable interval.
if (this._minElapsedMS) {
var delta = currentTime - this._lastFrame | 0;
if (delta < this._minElapsedMS) {
return;
}
this._lastFrame = currentTime - (delta % this._minElapsedMS);
}
previous = current;
current = current.next;
this.deltaMS = elapsedMS;
this.deltaTime = this.deltaMS * settings.TARGET_FPMS;
// Cache a local reference, in-case ticker is destroyed
// during the emit, we can still check for head.next
var head = this._head;
// Invoke listeners added to internal emitter
var listener = head.next;
while (listener) {
listener = listener.emit(this.deltaTime);
}
if (!head.next) {
this._cancelIfNeeded();
}
}
// Not yet connected
if (!listener.previous)
{
listener.connect(previous);
else {
this.deltaTime = this.deltaMS = this.elapsedMS = 0;
}
}
this._startIfPossible();
return this;
};
/**
* Removes any handlers matching the function and context parameters.
* If no handlers are left after removing, then it cancels the animation frame.
*
* @param {Function} fn - The listener function to be removed
* @param {*} [context] - The listener context to be removed
* @returns {PIXI.Ticker} This instance of a ticker
*/
Ticker.prototype.remove = function remove (fn, context)
{
var listener = this._head.next;
while (listener)
{
// We found a match, lets remove it
// no break to delete all possible matches
// incase a listener was added 2+ times
if (listener.match(fn, context))
{
listener = listener.destroy();
}
else
{
listener = listener.next;
}
}
if (!this._head.next)
{
this._cancelIfNeeded();
}
return this;
};
/**
* Starts the ticker. If the ticker has listeners
* a new animation frame is requested at this point.
*/
Ticker.prototype.start = function start ()
{
if (!this.started)
{
this.started = true;
this._requestIfNeeded();
}
};
/**
* Stops the ticker. If the ticker has requested
* an animation frame it is canceled at this point.
*/
Ticker.prototype.stop = function stop ()
{
if (this.started)
{
this.started = false;
this._cancelIfNeeded();
}
};
/**
* Destroy the ticker and don't use after this. Calling
* this method removes all references to internal events.
*/
Ticker.prototype.destroy = function destroy ()
{
if (!this._protected)
{
this.stop();
var listener = this._head.next;
while (listener)
{
listener = listener.destroy(true);
}
this._head.destroy();
this._head = null;
}
};
/**
* Triggers an update. An update entails setting the
* current {@link PIXI.Ticker#elapsedMS},
* the current {@link PIXI.Ticker#deltaTime},
* invoking all listeners with current deltaTime,
* and then finally setting {@link PIXI.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.
*
* @param {number} [currentTime=performance.now()] - the current time of execution
*/
Ticker.prototype.update = function update (currentTime)
{
if ( currentTime === void 0 ) currentTime = performance.now();
var elapsedMS;
// If the difference in time is zero or negative, we ignore most of the work done here.
// If there is no valid difference, then should be no reason to let anyone know about it.
// A zero delta, is exactly that, nothing should update.
//
// The difference in time can be negative, and no this does not mean time traveling.
// This can be the result of a race condition between when an animation frame is requested
// on the current JavaScript engine event loop, and when the ticker's start method is invoked
// (which invokes the internal _requestIfNeeded method). If a frame is requested before
// _requestIfNeeded is invoked, then the callback for the animation frame the ticker requests,
// can receive a time argument that can be less than the lastTime value that was set within
// _requestIfNeeded. This difference is in microseconds, but this is enough to cause problems.
//
// This check covers this browser engine timing issue, as well as if consumers pass an invalid
// currentTime value. This may happen if consumers opt-out of the autoStart, and update themselves.
if (currentTime > this.lastTime)
{
// Save uncapped elapsedMS for measurement
elapsedMS = this.elapsedMS = currentTime - this.lastTime;
// cap the milliseconds elapsed used for deltaTime
if (elapsedMS > this._maxElapsedMS)
{
elapsedMS = this._maxElapsedMS;
}
elapsedMS *= this.speed;
// If not enough time has passed, exit the function.
// Get ready for next frame by setting _lastFrame, but based on _minElapsedMS
// adjustment to ensure a relatively stable interval.
if (this._minElapsedMS)
{
var delta = currentTime - this._lastFrame | 0;
if (delta < this._minElapsedMS)
{
return;
this.lastTime = currentTime;
};
Object.defineProperty(Ticker.prototype, "FPS", {
/**
* The frames per second at which this ticker is running.
* The default is approximately 60 in most modern browsers.
* **Note:** This does not factor in the value of
* {@link PIXI.Ticker#speed}, which is specific
* to scaling {@link PIXI.Ticker#deltaTime}.
*
* @member {number}
* @readonly
*/
get: function () {
return 1000 / this.elapsedMS;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Ticker.prototype, "minFPS", {
/**
* Manages the maximum amount of milliseconds allowed to
* elapse between invoking {@link PIXI.Ticker#update}.
* This value is used to cap {@link PIXI.Ticker#deltaTime},
* but does not effect the measured value of {@link PIXI.Ticker#FPS}.
* When setting this property it is clamped to a value between
* `0` and `PIXI.settings.TARGET_FPMS * 1000`.
*
* @member {number}
* @default 10
*/
get: function () {
return 1000 / this._maxElapsedMS;
},
set: function (fps) {
// Minimum must be below the maxFPS
var minFPS = Math.min(this.maxFPS, fps);
// Must be at least 0, but below 1 / settings.TARGET_FPMS
var minFPMS = Math.min(Math.max(0, minFPS) / 1000, settings.TARGET_FPMS);
this._maxElapsedMS = 1 / minFPMS;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Ticker.prototype, "maxFPS", {
/**
* Manages the minimum amount of milliseconds required to
* elapse between invoking {@link PIXI.Ticker#update}.
* This will effect the measured value of {@link PIXI.Ticker#FPS}.
* If it is set to `0`, then there is no limit; PixiJS will render as many frames as it can.
* Otherwise it will be at least `minFPS`
*
* @member {number}
* @default 0
*/
get: function () {
if (this._minElapsedMS) {
return Math.round(1000 / this._minElapsedMS);
}
return 0;
},
set: function (fps) {
if (fps === 0) {
this._minElapsedMS = 0;
}
else {
// Max must be at least the minFPS
var maxFPS = Math.max(this.minFPS, fps);
this._minElapsedMS = 1 / (maxFPS / 1000);
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(Ticker, "shared", {
/**
* The shared ticker instance used by {@link PIXI.AnimatedSprite} and by
* {@link PIXI.VideoResource} to update animation frames / video textures.
*
* It may also be used by {@link PIXI.Application} if created with the `sharedTicker` option property set to true.
*
* The property {@link PIXI.Ticker#autoStart} is set to `true` for this instance.
* Please follow the examples for usage, including how to opt-out of auto-starting the shared ticker.
*
* @example
* let ticker = PIXI.Ticker.shared;
* // Set this to prevent starting this ticker when listeners are added.
* // By default this is true only for the PIXI.Ticker.shared instance.
* ticker.autoStart = false;
* // FYI, call this to ensure the ticker is stopped. It should be stopped
* // if you have not attempted to render anything yet.
* ticker.stop();
* // Call this when you are ready for a running shared ticker.
* ticker.start();
*
* @example
* // You may use the shared ticker to render...
* let renderer = PIXI.autoDetectRenderer();
* let stage = new PIXI.Container();
* document.body.appendChild(renderer.view);
* ticker.add(function (time) {
* renderer.render(stage);
* });
*
* @example
* // Or you can just update it manually.
* ticker.autoStart = false;
* ticker.stop();
* function animate(time) {
* ticker.update(time);
* renderer.render(stage);
* requestAnimationFrame(animate);
* }
* animate(performance.now());
*
* @member {PIXI.Ticker}
* @static
*/
get: function () {
if (!Ticker._shared) {
var shared = Ticker._shared = new Ticker();
shared.autoStart = true;
shared._protected = true;
}
return Ticker._shared;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Ticker, "system", {
/**
* The system ticker instance used by {@link PIXI.interaction.InteractionManager} and by
* {@link PIXI.BasePrepare} for core timing functionality that shouldn't usually need to be paused,
* unlike the `shared` ticker which drives visual animations and rendering which may want to be paused.
*
* The property {@link PIXI.Ticker#autoStart} is set to `true` for this instance.
*
* @member {PIXI.Ticker}
* @static
*/
get: function () {
if (!Ticker._system) {
var system = Ticker._system = new Ticker();
system.autoStart = true;
system._protected = true;
}
return Ticker._system;
},
enumerable: true,
configurable: true
});
return Ticker;
}());
this._lastFrame = currentTime - (delta % this._minElapsedMS);
}
this.deltaMS = elapsedMS;
this.deltaTime = this.deltaMS * settings.TARGET_FPMS;
// Cache a local reference, in-case ticker is destroyed
// during the emit, we can still check for head.next
var head = this._head;
// Invoke listeners added to internal emitter
var listener = head.next;
while (listener)
{
listener = listener.emit(this.deltaTime);
}
if (!head.next)
{
this._cancelIfNeeded();
}
}
else
{
this.deltaTime = this.deltaMS = this.elapsedMS = 0;
}
this.lastTime = currentTime;
};
/**
* The frames per second at which this ticker is running.
* The default is approximately 60 in most modern browsers.
* **Note:** This does not factor in the value of
* {@link PIXI.Ticker#speed}, which is specific
* to scaling {@link PIXI.Ticker#deltaTime}.
*
* @member {number}
* @readonly
*/
prototypeAccessors.FPS.get = function ()
{
return 1000 / this.elapsedMS;
};
/**
* Manages the maximum amount of milliseconds allowed to
* elapse between invoking {@link PIXI.Ticker#update}.
* This value is used to cap {@link PIXI.Ticker#deltaTime},
* but does not effect the measured value of {@link PIXI.Ticker#FPS}.
* When setting this property it is clamped to a value between
* `0` and `PIXI.settings.TARGET_FPMS * 1000`.
*
* @member {number}
* @default 10
*/
prototypeAccessors.minFPS.get = function ()
{
return 1000 / this._maxElapsedMS;
};
prototypeAccessors.minFPS.set = function (fps) // eslint-disable-line require-jsdoc
{
// Minimum must be below the maxFPS
var minFPS = Math.min(this.maxFPS, fps);
// Must be at least 0, but below 1 / settings.TARGET_FPMS
var minFPMS = Math.min(Math.max(0, minFPS) / 1000, settings.TARGET_FPMS);
this._maxElapsedMS = 1 / minFPMS;
};
/**
* Manages the minimum amount of milliseconds required to
* elapse between invoking {@link PIXI.Ticker#update}.
* This will effect the measured value of {@link PIXI.Ticker#FPS}.
* If it is set to `0`, then there is no limit; PixiJS will render as many frames as it can.
* Otherwise it will be at least `minFPS`
*
* @member {number}
* @default 0
*/
prototypeAccessors.maxFPS.get = function ()
{
if (this._minElapsedMS)
{
return Math.round(1000 / this._minElapsedMS);
}
return 0;
};
prototypeAccessors.maxFPS.set = function (fps)
{
if (fps === 0)
{
this._minElapsedMS = 0;
}
else
{
// Max must be at least the minFPS
var maxFPS = Math.max(this.minFPS, fps);
this._minElapsedMS = 1 / (maxFPS / 1000);
}
};
/**
* The shared ticker instance used by {@link PIXI.AnimatedSprite} and by
* {@link PIXI.VideoResource} to update animation frames / video textures.
*
* It may also be used by {@link PIXI.Application} if created with the `sharedTicker` option property set to true.
*
* The property {@link PIXI.Ticker#autoStart} is set to `true` for this instance.
* Please follow the examples for usage, including how to opt-out of auto-starting the shared ticker.
*
* @example
* let ticker = PIXI.Ticker.shared;
* // Set this to prevent starting this ticker when listeners are added.
* // By default this is true only for the PIXI.Ticker.shared instance.
* ticker.autoStart = false;
* // FYI, call this to ensure the ticker is stopped. It should be stopped
* // if you have not attempted to render anything yet.
* ticker.stop();
* // Call this when you are ready for a running shared ticker.
* ticker.start();
*
* @example
* // You may use the shared ticker to render...
* let renderer = PIXI.autoDetectRenderer();
* let stage = new PIXI.Container();
* document.body.appendChild(renderer.view);
* ticker.add(function (time) {
* renderer.render(stage);
* });
*
* @example
* // Or you can just update it manually.
* ticker.autoStart = false;
* ticker.stop();
* function animate(time) {
* ticker.update(time);
* renderer.render(stage);
* requestAnimationFrame(animate);
* }
* animate(performance.now());
*
* @member {PIXI.Ticker}
* @static
*/
staticAccessors.shared.get = function ()
{
if (!Ticker._shared)
{
var shared = Ticker._shared = new Ticker();
shared.autoStart = true;
shared._protected = true;
}
return Ticker._shared;
};
/**
* The system ticker instance used by {@link PIXI.interaction.InteractionManager} and by
* {@link PIXI.BasePrepare} for core timing functionality that shouldn't usually need to be paused,
* unlike the `shared` ticker which drives visual animations and rendering which may want to be paused.
*
* The property {@link PIXI.Ticker#autoStart} is set to `true` for this instance.
*
* @member {PIXI.Ticker}
* @static
*/
staticAccessors.system.get = function ()
{
if (!Ticker._system)
{
var system = Ticker._system = new Ticker();
system.autoStart = true;
system._protected = true;
}
return Ticker._system;
};
Object.defineProperties( Ticker.prototype, prototypeAccessors );
Object.defineProperties( Ticker, staticAccessors );
/**
* Middleware for for Application Ticker.

@@ -863,98 +741,90 @@ *

*/
var TickerPlugin = function TickerPlugin () {};
TickerPlugin.init = function init (options)
{
var this$1 = this;
// Set default
options = Object.assign({
autoStart: true,
sharedTicker: false,
}, options);
// Create ticker setter
Object.defineProperty(this, 'ticker',
{
set: function set(ticker)
{
if (this._ticker)
{
var TickerPlugin = /** @class */ (function () {
function TickerPlugin() {
}
/**
* Initialize the plugin with scope of application instance
*
* @static
* @private
* @param {object} [options] - See application options
*/
TickerPlugin.init = function (options) {
var _this = this;
// Set default
options = Object.assign({
autoStart: true,
sharedTicker: false,
}, options);
// Create ticker setter
Object.defineProperty(this, 'ticker', {
set: function (ticker) {
if (this._ticker) {
this._ticker.remove(this.render, this);
}
this._ticker = ticker;
if (ticker)
{
if (ticker) {
ticker.add(this.render, this, UPDATE_PRIORITY.LOW);
}
},
get: function get()
{
get: function () {
return this._ticker;
},
});
/**
* Convenience method for stopping the render.
*
* @method PIXI.Application#stop
*/
this.stop = function () {
this$1._ticker.stop();
/**
* Convenience method for stopping the render.
*
* @method PIXI.Application#stop
*/
this.stop = function () {
_this._ticker.stop();
};
/**
* Convenience method for starting the render.
*
* @method PIXI.Application#start
*/
this.start = function () {
_this._ticker.start();
};
/**
* Internal reference to the ticker.
*
* @type {PIXI.Ticker}
* @name _ticker
* @memberof PIXI.Application#
* @private
*/
this._ticker = null;
/**
* Ticker for doing render updates.
*
* @type {PIXI.Ticker}
* @name ticker
* @memberof PIXI.Application#
* @default PIXI.Ticker.shared
*/
this.ticker = options.sharedTicker ? Ticker.shared : new Ticker();
// Start the rendering
if (options.autoStart) {
this.start();
}
};
/**
* Convenience method for starting the render.
* Clean up the ticker, scoped to application.
*
* @method PIXI.Application#start
* @static
* @private
*/
this.start = function () {
this$1._ticker.start();
TickerPlugin.destroy = function () {
if (this._ticker) {
var oldTicker = this._ticker;
this.ticker = null;
oldTicker.destroy();
}
};
return TickerPlugin;
}());
/**
* Internal reference to the ticker.
*
* @type {PIXI.Ticker}
* @name _ticker
* @memberof PIXI.Application#
* @private
*/
this._ticker = null;
/**
* Ticker for doing render updates.
*
* @type {PIXI.Ticker}
* @name ticker
* @memberof PIXI.Application#
* @default PIXI.Ticker.shared
*/
this.ticker = options.sharedTicker ? Ticker.shared : new Ticker();
// Start the rendering
if (options.autoStart)
{
this.start();
}
};
/**
* Clean up the ticker, scoped to application.
*
* @static
* @private
*/
TickerPlugin.destroy = function destroy ()
{
if (this._ticker)
{
var oldTicker = this._ticker;
this.ticker = null;
oldTicker.destroy();
}
};
export { Ticker, TickerPlugin, UPDATE_PRIORITY };
//# sourceMappingURL=ticker.es.js.map
/*!
* @pixi/ticker - v5.1.3
* Compiled Mon, 09 Sep 2019 04:51:53 UTC
* @pixi/ticker - v5.2.0
* Compiled Wed, 06 Nov 2019 02:32:43 UTC
*

@@ -34,3 +34,3 @@ * @pixi/ticker is licensed under the MIT License.

* @memberof PIXI
* @type {object}
* @enum {number}
* @property {number} INTERACTION=50 Highest priority, used for {@link PIXI.interaction.InteractionManager}

@@ -42,9 +42,9 @@ * @property {number} HIGH=25 High priority updating, {@link PIXI.VideoBaseTexture} and {@link PIXI.AnimatedSprite}

*/
var UPDATE_PRIORITY = {
INTERACTION: 50,
HIGH: 25,
NORMAL: 0,
LOW: -25,
UTILITY: -50,
};
(function (UPDATE_PRIORITY) {
UPDATE_PRIORITY[UPDATE_PRIORITY["INTERACTION"] = 50] = "INTERACTION";
UPDATE_PRIORITY[UPDATE_PRIORITY["HIGH"] = 25] = "HIGH";
UPDATE_PRIORITY[UPDATE_PRIORITY["NORMAL"] = 0] = "NORMAL";
UPDATE_PRIORITY[UPDATE_PRIORITY["LOW"] = -25] = "LOW";
UPDATE_PRIORITY[UPDATE_PRIORITY["UTILITY"] = -50] = "UTILITY";
})(exports.UPDATE_PRIORITY || (exports.UPDATE_PRIORITY = {}));

@@ -58,162 +58,138 @@ /**

*/
var TickerListener = function TickerListener(fn, context, priority, once)
{
if ( context === void 0 ) context = null;
if ( priority === void 0 ) priority = 0;
if ( once === void 0 ) once = false;
var TickerListener = /** @class */ (function () {
/**
* The handler function to execute.
* Constructor
* @private
* @member {Function}
* @param {Function} fn - The listener function to be added for one update
* @param {*} [context=null] - The listener context
* @param {number} [priority=0] - The priority for emitting
* @param {boolean} [once=false] - If the handler should fire once
*/
this.fn = fn;
function TickerListener(fn, context, priority, once) {
if (context === void 0) { context = null; }
if (priority === void 0) { priority = 0; }
if (once === void 0) { once = false; }
/**
* The handler function to execute.
* @private
* @member {Function}
*/
this.fn = fn;
/**
* The calling to execute.
* @private
* @member {*}
*/
this.context = context;
/**
* The current priority.
* @private
* @member {number}
*/
this.priority = priority;
/**
* If this should only execute once.
* @private
* @member {boolean}
*/
this.once = once;
/**
* The next item in chain.
* @private
* @member {TickerListener}
*/
this.next = null;
/**
* The previous item in chain.
* @private
* @member {TickerListener}
*/
this.previous = null;
/**
* `true` if this listener has been destroyed already.
* @member {boolean}
* @private
*/
this._destroyed = false;
}
/**
* The calling to execute.
* Simple compare function to figure out if a function and context match.
* @private
* @member {*}
* @param {Function} fn - The listener function to be added for one update
* @param {any} [context] - The listener context
* @return {boolean} `true` if the listener match the arguments
*/
this.context = context;
TickerListener.prototype.match = function (fn, context) {
if (context === void 0) { context = null; }
return this.fn === fn && this.context === context;
};
/**
* The current priority.
* Emit by calling the current function.
* @private
* @member {number}
* @param {number} deltaTime - time since the last emit.
* @return {TickerListener} Next ticker
*/
this.priority = priority;
TickerListener.prototype.emit = function (deltaTime) {
if (this.fn) {
if (this.context) {
this.fn.call(this.context, deltaTime);
}
else {
this.fn(deltaTime);
}
}
var redirect = this.next;
if (this.once) {
this.destroy(true);
}
// Soft-destroying should remove
// the next reference
if (this._destroyed) {
this.next = null;
}
return redirect;
};
/**
* If this should only execute once.
* Connect to the list.
* @private
* @member {boolean}
* @param {TickerListener} previous - Input node, previous listener
*/
this.once = once;
TickerListener.prototype.connect = function (previous) {
this.previous = previous;
if (previous.next) {
previous.next.previous = this;
}
this.next = previous.next;
previous.next = this;
};
/**
* The next item in chain.
* Destroy and don't use after this.
* @private
* @member {TickerListener}
* @param {boolean} [hard = false] `true` to remove the `next` reference, this
* is considered a hard destroy. Soft destroy maintains the next reference.
* @return {TickerListener} The listener to redirect while emitting or removing.
*/
this.next = null;
/**
* The previous item in chain.
* @private
* @member {TickerListener}
*/
this.previous = null;
/**
* `true` if this listener has been destroyed already.
* @member {boolean}
* @private
*/
this._destroyed = false;
};
/**
* Simple compare function to figure out if a function and context match.
* @private
* @param {Function} fn - The listener function to be added for one update
* @param {Function} context - The listener context
* @return {boolean} `true` if the listener match the arguments
*/
TickerListener.prototype.match = function match (fn, context)
{
context = context || null;
return this.fn === fn && this.context === context;
};
/**
* Emit by calling the current function.
* @private
* @param {number} deltaTime - time since the last emit.
* @return {TickerListener} Next ticker
*/
TickerListener.prototype.emit = function emit (deltaTime)
{
if (this.fn)
{
if (this.context)
{
this.fn.call(this.context, deltaTime);
TickerListener.prototype.destroy = function (hard) {
if (hard === void 0) { hard = false; }
this._destroyed = true;
this.fn = null;
this.context = null;
// Disconnect, hook up next and previous
if (this.previous) {
this.previous.next = this.next;
}
else
{
this.fn(deltaTime);
if (this.next) {
this.next.previous = this.previous;
}
}
// Redirect to the next item
var redirect = this.next;
// Remove references
this.next = hard ? null : redirect;
this.previous = null;
return redirect;
};
return TickerListener;
}());
var redirect = this.next;
if (this.once)
{
this.destroy(true);
}
// Soft-destroying should remove
// the next reference
if (this._destroyed)
{
this.next = null;
}
return redirect;
};
/**
* Connect to the list.
* @private
* @param {TickerListener} previous - Input node, previous listener
*/
TickerListener.prototype.connect = function connect (previous)
{
this.previous = previous;
if (previous.next)
{
previous.next.previous = this;
}
this.next = previous.next;
previous.next = this;
};
/**
* Destroy and don't use after this.
* @private
* @param {boolean} [hard = false] `true` to remove the `next` reference, this
* is considered a hard destroy. Soft destroy maintains the next reference.
* @return {TickerListener} The listener to redirect while emitting or removing.
*/
TickerListener.prototype.destroy = function destroy (hard)
{
if ( hard === void 0 ) hard = false;
this._destroyed = true;
this.fn = null;
this.context = null;
// Disconnect, hook up next and previous
if (this.previous)
{
this.previous.next = this.next;
}
if (this.next)
{
this.next.previous = this.previous;
}
// Redirect to the next item
var redirect = this.next;
// Remove references
this.next = hard ? null : redirect;
this.previous = null;
return redirect;
};
/**
* A Ticker class that runs an update loop that other objects listen to.

@@ -227,631 +203,532 @@ *

*/
var Ticker = function Ticker()
{
var this$1 = this;
var Ticker = /** @class */ (function () {
function Ticker() {
var _this = this;
/**
* The first listener. All new listeners added are chained on this.
* @private
* @type {TickerListener}
*/
this._head = new TickerListener(null, null, Infinity);
/**
* Internal current frame request ID
* @type {?number}
* @private
*/
this._requestId = null;
/**
* Internal value managed by minFPS property setter and getter.
* This is the maximum allowed milliseconds between updates.
* @type {number}
* @private
*/
this._maxElapsedMS = 100;
/**
* Internal value managed by maxFPS property setter and getter.
* This is the minimum allowed milliseconds between updates.
* @type {number}
* @private
*/
this._minElapsedMS = 0;
/**
* Whether or not this ticker should invoke the method
* {@link PIXI.Ticker#start} automatically
* when a listener is added.
*
* @member {boolean}
* @default false
*/
this.autoStart = false;
/**
* Scalar time value from last frame to this frame.
* This value is capped by setting {@link PIXI.Ticker#minFPS}
* and is scaled with {@link PIXI.Ticker#speed}.
* **Note:** The cap may be exceeded by scaling.
*
* @member {number}
* @default 1
*/
this.deltaTime = 1;
/**
* Scaler time elapsed in milliseconds from last frame to this frame.
* This value is capped by setting {@link PIXI.Ticker#minFPS}
* and is scaled with {@link PIXI.Ticker#speed}.
* **Note:** The cap may be exceeded by scaling.
* If the platform supports DOMHighResTimeStamp,
* this value will have a precision of 1 µs.
* Defaults to target frame time
*
* @member {number}
* @default 16.66
*/
this.deltaMS = 1 / settings.settings.TARGET_FPMS;
/**
* Time elapsed in milliseconds from last frame to this frame.
* Opposed to what the scalar {@link PIXI.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
*
* @member {number}
* @default 16.66
*/
this.elapsedMS = 1 / settings.settings.TARGET_FPMS;
/**
* The last time {@link PIXI.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.
*
* @member {number}
* @default -1
*/
this.lastTime = -1;
/**
* Factor of current {@link PIXI.Ticker#deltaTime}.
* @example
* // Scales ticker.deltaTime to what would be
* // the equivalent of approximately 120 FPS
* ticker.speed = 2;
*
* @member {number}
* @default 1
*/
this.speed = 1;
/**
* Whether or not this ticker has been started.
* `true` if {@link PIXI.Ticker#start} has been called.
* `false` if {@link PIXI.Ticker#stop} has been called.
* While `false`, this value may change to `true` in the
* event of {@link PIXI.Ticker#autoStart} being `true`
* and a listener is added.
*
* @member {boolean}
* @default false
*/
this.started = false;
/**
* If enabled, deleting is disabled.
* @member {boolean}
* @default false
* @private
*/
this._protected = false;
/**
* The last time keyframe was executed.
* Maintains a relatively fixed interval with the previous value.
* @member {number}
* @default -1
* @private
*/
this._lastFrame = -1;
/**
* Internal tick method bound to ticker instance.
* This is because in early 2015, Function.bind
* is still 60% slower in high performance scenarios.
* Also separating frame requests from update method
* so listeners may be called at any time and with
* any animation API, just invoke ticker.update(time).
*
* @private
* @param {number} time - Time since last tick.
*/
this._tick = function (time) {
_this._requestId = null;
if (_this.started) {
// Invoke listeners now
_this.update(time);
// Listener side effects may have modified ticker state.
if (_this.started && _this._requestId === null && _this._head.next) {
_this._requestId = requestAnimationFrame(_this._tick);
}
}
};
}
/**
* The first listener. All new listeners added are chained on this.
* Conditionally requests a new animation frame.
* If a frame has not already been requested, and if the internal
* emitter has listeners, a new frame is requested.
*
* @private
* @type {TickerListener}
*/
this._head = new TickerListener(null, null, Infinity);
Ticker.prototype._requestIfNeeded = function () {
if (this._requestId === null && this._head.next) {
// ensure callbacks get correct delta
this.lastTime = performance.now();
this._lastFrame = this.lastTime;
this._requestId = requestAnimationFrame(this._tick);
}
};
/**
* Internal current frame request ID
* @type {?number}
* Conditionally cancels a pending animation frame.
*
* @private
*/
this._requestId = null;
Ticker.prototype._cancelIfNeeded = function () {
if (this._requestId !== null) {
cancelAnimationFrame(this._requestId);
this._requestId = null;
}
};
/**
* Internal value managed by minFPS property setter and getter.
* This is the maximum allowed milliseconds between updates.
* @type {number}
* Conditionally requests a new animation frame.
* If the ticker has been started it checks if a frame has not already
* been requested, and if the internal emitter has listeners. If these
* conditions are met, a new frame is requested. If the ticker has not
* been started, but autoStart is `true`, then the ticker starts now,
* and continues with the previous conditions to request a new frame.
*
* @private
*/
this._maxElapsedMS = 100;
Ticker.prototype._startIfPossible = function () {
if (this.started) {
this._requestIfNeeded();
}
else if (this.autoStart) {
this.start();
}
};
/**
* Internal value managed by maxFPS property setter and getter.
* This is the minimum allowed milliseconds between updates.
* @private
*/
this._minElapsedMS = 0;
/**
* Whether or not this ticker should invoke the method
* {@link PIXI.Ticker#start} automatically
* when a listener is added.
* Register a handler for tick events. Calls continuously unless
* it is removed or the ticker is stopped.
*
* @member {boolean}
* @default false
* @param {Function} fn - The listener function to be added for updates
* @param {*} [context] - The listener context
* @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting
* @returns {PIXI.Ticker} This instance of a ticker
*/
this.autoStart = false;
Ticker.prototype.add = function (fn, context, priority) {
if (priority === void 0) { priority = exports.UPDATE_PRIORITY.NORMAL; }
return this._addListener(new TickerListener(fn, context, priority));
};
/**
* Scalar time value from last frame to this frame.
* This value is capped by setting {@link PIXI.Ticker#minFPS}
* and is scaled with {@link PIXI.Ticker#speed}.
* **Note:** The cap may be exceeded by scaling.
* Add a handler for the tick event which is only execute once.
*
* @member {number}
* @default 1
* @param {Function} fn - The listener function to be added for one update
* @param {*} [context] - The listener context
* @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting
* @returns {PIXI.Ticker} This instance of a ticker
*/
this.deltaTime = 1;
Ticker.prototype.addOnce = function (fn, context, priority) {
if (priority === void 0) { priority = exports.UPDATE_PRIORITY.NORMAL; }
return this._addListener(new TickerListener(fn, context, priority, true));
};
/**
* Scaler time elapsed in milliseconds from last frame to this frame.
* This value is capped by setting {@link PIXI.Ticker#minFPS}
* and is scaled with {@link PIXI.Ticker#speed}.
* **Note:** The cap may be exceeded by scaling.
* If the platform supports DOMHighResTimeStamp,
* this value will have a precision of 1 µs.
* Defaults to target frame time
* Internally adds the event handler so that it can be sorted by priority.
* Priority allows certain handler (user, AnimatedSprite, Interaction) to be run
* before the rendering.
*
* @member {number}
* @default 16.66
* @private
* @param {TickerListener} listener - Current listener being added.
* @returns {PIXI.Ticker} This instance of a ticker
*/
this.deltaMS = 1 / settings.settings.TARGET_FPMS;
Ticker.prototype._addListener = function (listener) {
// For attaching to head
var current = this._head.next;
var previous = this._head;
// Add the first item
if (!current) {
listener.connect(previous);
}
else {
// Go from highest to lowest priority
while (current) {
if (listener.priority > current.priority) {
listener.connect(previous);
break;
}
previous = current;
current = current.next;
}
// Not yet connected
if (!listener.previous) {
listener.connect(previous);
}
}
this._startIfPossible();
return this;
};
/**
* Time elapsed in milliseconds from last frame to this frame.
* Opposed to what the scalar {@link PIXI.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
* Removes any handlers matching the function and context parameters.
* If no handlers are left after removing, then it cancels the animation frame.
*
* @member {number}
* @default 16.66
* @param {Function} fn - The listener function to be removed
* @param {*} [context] - The listener context to be removed
* @returns {PIXI.Ticker} This instance of a ticker
*/
this.elapsedMS = 1 / settings.settings.TARGET_FPMS;
Ticker.prototype.remove = function (fn, context) {
var listener = this._head.next;
while (listener) {
// We found a match, lets remove it
// no break to delete all possible matches
// incase a listener was added 2+ times
if (listener.match(fn, context)) {
listener = listener.destroy();
}
else {
listener = listener.next;
}
}
if (!this._head.next) {
this._cancelIfNeeded();
}
return this;
};
/**
* The last time {@link PIXI.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.
*
* @member {number}
* @default -1
* Starts the ticker. If the ticker has listeners
* a new animation frame is requested at this point.
*/
this.lastTime = -1;
Ticker.prototype.start = function () {
if (!this.started) {
this.started = true;
this._requestIfNeeded();
}
};
/**
* Factor of current {@link PIXI.Ticker#deltaTime}.
* @example
* // Scales ticker.deltaTime to what would be
* // the equivalent of approximately 120 FPS
* ticker.speed = 2;
*
* @member {number}
* @default 1
* Stops the ticker. If the ticker has requested
* an animation frame it is canceled at this point.
*/
this.speed = 1;
Ticker.prototype.stop = function () {
if (this.started) {
this.started = false;
this._cancelIfNeeded();
}
};
/**
* Whether or not this ticker has been started.
* `true` if {@link PIXI.Ticker#start} has been called.
* `false` if {@link PIXI.Ticker#stop} has been called.
* While `false`, this value may change to `true` in the
* event of {@link PIXI.Ticker#autoStart} being `true`
* and a listener is added.
*
* @member {boolean}
* @default false
* Destroy the ticker and don't use after this. Calling
* this method removes all references to internal events.
*/
this.started = false;
Ticker.prototype.destroy = function () {
if (!this._protected) {
this.stop();
var listener = this._head.next;
while (listener) {
listener = listener.destroy(true);
}
this._head.destroy();
this._head = null;
}
};
/**
* If enabled, deleting is disabled.
* @member {boolean}
* @default false
* @private
*/
this._protected = false;
/**
* The last time keyframe was executed.
* Maintains a relatively fixed interval with the previous value.
* @member {number}
* @default -1
* @private
*/
this._lastFrame = -1;
/**
* Internal tick method bound to ticker instance.
* This is because in early 2015, Function.bind
* is still 60% slower in high performance scenarios.
* Also separating frame requests from update method
* so listeners may be called at any time and with
* any animation API, just invoke ticker.update(time).
* Triggers an update. An update entails setting the
* current {@link PIXI.Ticker#elapsedMS},
* the current {@link PIXI.Ticker#deltaTime},
* invoking all listeners with current deltaTime,
* and then finally setting {@link PIXI.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.
*
* @private
* @param {number} time - Time since last tick.
* @param {number} [currentTime=performance.now()] - the current time of execution
*/
this._tick = function (time) {
this$1._requestId = null;
if (this$1.started)
{
// Invoke listeners now
this$1.update(time);
// Listener side effects may have modified ticker state.
if (this$1.started && this$1._requestId === null && this$1._head.next)
{
this$1._requestId = requestAnimationFrame(this$1._tick);
Ticker.prototype.update = function (currentTime) {
if (currentTime === void 0) { currentTime = performance.now(); }
var elapsedMS;
// If the difference in time is zero or negative, we ignore most of the work done here.
// If there is no valid difference, then should be no reason to let anyone know about it.
// A zero delta, is exactly that, nothing should update.
//
// The difference in time can be negative, and no this does not mean time traveling.
// This can be the result of a race condition between when an animation frame is requested
// on the current JavaScript engine event loop, and when the ticker's start method is invoked
// (which invokes the internal _requestIfNeeded method). If a frame is requested before
// _requestIfNeeded is invoked, then the callback for the animation frame the ticker requests,
// can receive a time argument that can be less than the lastTime value that was set within
// _requestIfNeeded. This difference is in microseconds, but this is enough to cause problems.
//
// This check covers this browser engine timing issue, as well as if consumers pass an invalid
// currentTime value. This may happen if consumers opt-out of the autoStart, and update themselves.
if (currentTime > this.lastTime) {
// Save uncapped elapsedMS for measurement
elapsedMS = this.elapsedMS = currentTime - this.lastTime;
// cap the milliseconds elapsed used for deltaTime
if (elapsedMS > this._maxElapsedMS) {
elapsedMS = this._maxElapsedMS;
}
}
};
};
var prototypeAccessors = { FPS: { configurable: true },minFPS: { configurable: true },maxFPS: { configurable: true } };
var staticAccessors = { shared: { configurable: true },system: { configurable: true } };
/**
* Conditionally requests a new animation frame.
* If a frame has not already been requested, and if the internal
* emitter has listeners, a new frame is requested.
*
* @private
*/
Ticker.prototype._requestIfNeeded = function _requestIfNeeded ()
{
if (this._requestId === null && this._head.next)
{
// ensure callbacks get correct delta
this.lastTime = performance.now();
this._lastFrame = this.lastTime;
this._requestId = requestAnimationFrame(this._tick);
}
};
/**
* Conditionally cancels a pending animation frame.
*
* @private
*/
Ticker.prototype._cancelIfNeeded = function _cancelIfNeeded ()
{
if (this._requestId !== null)
{
cancelAnimationFrame(this._requestId);
this._requestId = null;
}
};
/**
* Conditionally requests a new animation frame.
* If the ticker has been started it checks if a frame has not already
* been requested, and if the internal emitter has listeners. If these
* conditions are met, a new frame is requested. If the ticker has not
* been started, but autoStart is `true`, then the ticker starts now,
* and continues with the previous conditions to request a new frame.
*
* @private
*/
Ticker.prototype._startIfPossible = function _startIfPossible ()
{
if (this.started)
{
this._requestIfNeeded();
}
else if (this.autoStart)
{
this.start();
}
};
/**
* Register a handler for tick events. Calls continuously unless
* it is removed or the ticker is stopped.
*
* @param {Function} fn - The listener function to be added for updates
* @param {*} [context] - The listener context
* @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting
* @returns {PIXI.Ticker} This instance of a ticker
*/
Ticker.prototype.add = function add (fn, context, priority)
{
if ( priority === void 0 ) priority = UPDATE_PRIORITY.NORMAL;
return this._addListener(new TickerListener(fn, context, priority));
};
/**
* Add a handler for the tick event which is only execute once.
*
* @param {Function} fn - The listener function to be added for one update
* @param {*} [context] - The listener context
* @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting
* @returns {PIXI.Ticker} This instance of a ticker
*/
Ticker.prototype.addOnce = function addOnce (fn, context, priority)
{
if ( priority === void 0 ) priority = UPDATE_PRIORITY.NORMAL;
return this._addListener(new TickerListener(fn, context, priority, true));
};
/**
* Internally adds the event handler so that it can be sorted by priority.
* Priority allows certain handler (user, AnimatedSprite, Interaction) to be run
* before the rendering.
*
* @private
* @param {TickerListener} listener - Current listener being added.
* @returns {PIXI.Ticker} This instance of a ticker
*/
Ticker.prototype._addListener = function _addListener (listener)
{
// For attaching to head
var current = this._head.next;
var previous = this._head;
// Add the first item
if (!current)
{
listener.connect(previous);
}
else
{
// Go from highest to lowest priority
while (current)
{
if (listener.priority > current.priority)
{
listener.connect(previous);
break;
elapsedMS *= this.speed;
// If not enough time has passed, exit the function.
// Get ready for next frame by setting _lastFrame, but based on _minElapsedMS
// adjustment to ensure a relatively stable interval.
if (this._minElapsedMS) {
var delta = currentTime - this._lastFrame | 0;
if (delta < this._minElapsedMS) {
return;
}
this._lastFrame = currentTime - (delta % this._minElapsedMS);
}
previous = current;
current = current.next;
this.deltaMS = elapsedMS;
this.deltaTime = this.deltaMS * settings.settings.TARGET_FPMS;
// Cache a local reference, in-case ticker is destroyed
// during the emit, we can still check for head.next
var head = this._head;
// Invoke listeners added to internal emitter
var listener = head.next;
while (listener) {
listener = listener.emit(this.deltaTime);
}
if (!head.next) {
this._cancelIfNeeded();
}
}
// Not yet connected
if (!listener.previous)
{
listener.connect(previous);
else {
this.deltaTime = this.deltaMS = this.elapsedMS = 0;
}
}
this._startIfPossible();
return this;
};
/**
* Removes any handlers matching the function and context parameters.
* If no handlers are left after removing, then it cancels the animation frame.
*
* @param {Function} fn - The listener function to be removed
* @param {*} [context] - The listener context to be removed
* @returns {PIXI.Ticker} This instance of a ticker
*/
Ticker.prototype.remove = function remove (fn, context)
{
var listener = this._head.next;
while (listener)
{
// We found a match, lets remove it
// no break to delete all possible matches
// incase a listener was added 2+ times
if (listener.match(fn, context))
{
listener = listener.destroy();
}
else
{
listener = listener.next;
}
}
if (!this._head.next)
{
this._cancelIfNeeded();
}
return this;
};
/**
* Starts the ticker. If the ticker has listeners
* a new animation frame is requested at this point.
*/
Ticker.prototype.start = function start ()
{
if (!this.started)
{
this.started = true;
this._requestIfNeeded();
}
};
/**
* Stops the ticker. If the ticker has requested
* an animation frame it is canceled at this point.
*/
Ticker.prototype.stop = function stop ()
{
if (this.started)
{
this.started = false;
this._cancelIfNeeded();
}
};
/**
* Destroy the ticker and don't use after this. Calling
* this method removes all references to internal events.
*/
Ticker.prototype.destroy = function destroy ()
{
if (!this._protected)
{
this.stop();
var listener = this._head.next;
while (listener)
{
listener = listener.destroy(true);
}
this._head.destroy();
this._head = null;
}
};
/**
* Triggers an update. An update entails setting the
* current {@link PIXI.Ticker#elapsedMS},
* the current {@link PIXI.Ticker#deltaTime},
* invoking all listeners with current deltaTime,
* and then finally setting {@link PIXI.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.
*
* @param {number} [currentTime=performance.now()] - the current time of execution
*/
Ticker.prototype.update = function update (currentTime)
{
if ( currentTime === void 0 ) currentTime = performance.now();
var elapsedMS;
// If the difference in time is zero or negative, we ignore most of the work done here.
// If there is no valid difference, then should be no reason to let anyone know about it.
// A zero delta, is exactly that, nothing should update.
//
// The difference in time can be negative, and no this does not mean time traveling.
// This can be the result of a race condition between when an animation frame is requested
// on the current JavaScript engine event loop, and when the ticker's start method is invoked
// (which invokes the internal _requestIfNeeded method). If a frame is requested before
// _requestIfNeeded is invoked, then the callback for the animation frame the ticker requests,
// can receive a time argument that can be less than the lastTime value that was set within
// _requestIfNeeded. This difference is in microseconds, but this is enough to cause problems.
//
// This check covers this browser engine timing issue, as well as if consumers pass an invalid
// currentTime value. This may happen if consumers opt-out of the autoStart, and update themselves.
if (currentTime > this.lastTime)
{
// Save uncapped elapsedMS for measurement
elapsedMS = this.elapsedMS = currentTime - this.lastTime;
// cap the milliseconds elapsed used for deltaTime
if (elapsedMS > this._maxElapsedMS)
{
elapsedMS = this._maxElapsedMS;
}
elapsedMS *= this.speed;
// If not enough time has passed, exit the function.
// Get ready for next frame by setting _lastFrame, but based on _minElapsedMS
// adjustment to ensure a relatively stable interval.
if (this._minElapsedMS)
{
var delta = currentTime - this._lastFrame | 0;
if (delta < this._minElapsedMS)
{
return;
this.lastTime = currentTime;
};
Object.defineProperty(Ticker.prototype, "FPS", {
/**
* The frames per second at which this ticker is running.
* The default is approximately 60 in most modern browsers.
* **Note:** This does not factor in the value of
* {@link PIXI.Ticker#speed}, which is specific
* to scaling {@link PIXI.Ticker#deltaTime}.
*
* @member {number}
* @readonly
*/
get: function () {
return 1000 / this.elapsedMS;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Ticker.prototype, "minFPS", {
/**
* Manages the maximum amount of milliseconds allowed to
* elapse between invoking {@link PIXI.Ticker#update}.
* This value is used to cap {@link PIXI.Ticker#deltaTime},
* but does not effect the measured value of {@link PIXI.Ticker#FPS}.
* When setting this property it is clamped to a value between
* `0` and `PIXI.settings.TARGET_FPMS * 1000`.
*
* @member {number}
* @default 10
*/
get: function () {
return 1000 / this._maxElapsedMS;
},
set: function (fps) {
// Minimum must be below the maxFPS
var minFPS = Math.min(this.maxFPS, fps);
// Must be at least 0, but below 1 / settings.TARGET_FPMS
var minFPMS = Math.min(Math.max(0, minFPS) / 1000, settings.settings.TARGET_FPMS);
this._maxElapsedMS = 1 / minFPMS;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Ticker.prototype, "maxFPS", {
/**
* Manages the minimum amount of milliseconds required to
* elapse between invoking {@link PIXI.Ticker#update}.
* This will effect the measured value of {@link PIXI.Ticker#FPS}.
* If it is set to `0`, then there is no limit; PixiJS will render as many frames as it can.
* Otherwise it will be at least `minFPS`
*
* @member {number}
* @default 0
*/
get: function () {
if (this._minElapsedMS) {
return Math.round(1000 / this._minElapsedMS);
}
return 0;
},
set: function (fps) {
if (fps === 0) {
this._minElapsedMS = 0;
}
else {
// Max must be at least the minFPS
var maxFPS = Math.max(this.minFPS, fps);
this._minElapsedMS = 1 / (maxFPS / 1000);
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(Ticker, "shared", {
/**
* The shared ticker instance used by {@link PIXI.AnimatedSprite} and by
* {@link PIXI.VideoResource} to update animation frames / video textures.
*
* It may also be used by {@link PIXI.Application} if created with the `sharedTicker` option property set to true.
*
* The property {@link PIXI.Ticker#autoStart} is set to `true` for this instance.
* Please follow the examples for usage, including how to opt-out of auto-starting the shared ticker.
*
* @example
* let ticker = PIXI.Ticker.shared;
* // Set this to prevent starting this ticker when listeners are added.
* // By default this is true only for the PIXI.Ticker.shared instance.
* ticker.autoStart = false;
* // FYI, call this to ensure the ticker is stopped. It should be stopped
* // if you have not attempted to render anything yet.
* ticker.stop();
* // Call this when you are ready for a running shared ticker.
* ticker.start();
*
* @example
* // You may use the shared ticker to render...
* let renderer = PIXI.autoDetectRenderer();
* let stage = new PIXI.Container();
* document.body.appendChild(renderer.view);
* ticker.add(function (time) {
* renderer.render(stage);
* });
*
* @example
* // Or you can just update it manually.
* ticker.autoStart = false;
* ticker.stop();
* function animate(time) {
* ticker.update(time);
* renderer.render(stage);
* requestAnimationFrame(animate);
* }
* animate(performance.now());
*
* @member {PIXI.Ticker}
* @static
*/
get: function () {
if (!Ticker._shared) {
var shared = Ticker._shared = new Ticker();
shared.autoStart = true;
shared._protected = true;
}
return Ticker._shared;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Ticker, "system", {
/**
* The system ticker instance used by {@link PIXI.interaction.InteractionManager} and by
* {@link PIXI.BasePrepare} for core timing functionality that shouldn't usually need to be paused,
* unlike the `shared` ticker which drives visual animations and rendering which may want to be paused.
*
* The property {@link PIXI.Ticker#autoStart} is set to `true` for this instance.
*
* @member {PIXI.Ticker}
* @static
*/
get: function () {
if (!Ticker._system) {
var system = Ticker._system = new Ticker();
system.autoStart = true;
system._protected = true;
}
return Ticker._system;
},
enumerable: true,
configurable: true
});
return Ticker;
}());
this._lastFrame = currentTime - (delta % this._minElapsedMS);
}
this.deltaMS = elapsedMS;
this.deltaTime = this.deltaMS * settings.settings.TARGET_FPMS;
// Cache a local reference, in-case ticker is destroyed
// during the emit, we can still check for head.next
var head = this._head;
// Invoke listeners added to internal emitter
var listener = head.next;
while (listener)
{
listener = listener.emit(this.deltaTime);
}
if (!head.next)
{
this._cancelIfNeeded();
}
}
else
{
this.deltaTime = this.deltaMS = this.elapsedMS = 0;
}
this.lastTime = currentTime;
};
/**
* The frames per second at which this ticker is running.
* The default is approximately 60 in most modern browsers.
* **Note:** This does not factor in the value of
* {@link PIXI.Ticker#speed}, which is specific
* to scaling {@link PIXI.Ticker#deltaTime}.
*
* @member {number}
* @readonly
*/
prototypeAccessors.FPS.get = function ()
{
return 1000 / this.elapsedMS;
};
/**
* Manages the maximum amount of milliseconds allowed to
* elapse between invoking {@link PIXI.Ticker#update}.
* This value is used to cap {@link PIXI.Ticker#deltaTime},
* but does not effect the measured value of {@link PIXI.Ticker#FPS}.
* When setting this property it is clamped to a value between
* `0` and `PIXI.settings.TARGET_FPMS * 1000`.
*
* @member {number}
* @default 10
*/
prototypeAccessors.minFPS.get = function ()
{
return 1000 / this._maxElapsedMS;
};
prototypeAccessors.minFPS.set = function (fps) // eslint-disable-line require-jsdoc
{
// Minimum must be below the maxFPS
var minFPS = Math.min(this.maxFPS, fps);
// Must be at least 0, but below 1 / settings.TARGET_FPMS
var minFPMS = Math.min(Math.max(0, minFPS) / 1000, settings.settings.TARGET_FPMS);
this._maxElapsedMS = 1 / minFPMS;
};
/**
* Manages the minimum amount of milliseconds required to
* elapse between invoking {@link PIXI.Ticker#update}.
* This will effect the measured value of {@link PIXI.Ticker#FPS}.
* If it is set to `0`, then there is no limit; PixiJS will render as many frames as it can.
* Otherwise it will be at least `minFPS`
*
* @member {number}
* @default 0
*/
prototypeAccessors.maxFPS.get = function ()
{
if (this._minElapsedMS)
{
return Math.round(1000 / this._minElapsedMS);
}
return 0;
};
prototypeAccessors.maxFPS.set = function (fps)
{
if (fps === 0)
{
this._minElapsedMS = 0;
}
else
{
// Max must be at least the minFPS
var maxFPS = Math.max(this.minFPS, fps);
this._minElapsedMS = 1 / (maxFPS / 1000);
}
};
/**
* The shared ticker instance used by {@link PIXI.AnimatedSprite} and by
* {@link PIXI.VideoResource} to update animation frames / video textures.
*
* It may also be used by {@link PIXI.Application} if created with the `sharedTicker` option property set to true.
*
* The property {@link PIXI.Ticker#autoStart} is set to `true` for this instance.
* Please follow the examples for usage, including how to opt-out of auto-starting the shared ticker.
*
* @example
* let ticker = PIXI.Ticker.shared;
* // Set this to prevent starting this ticker when listeners are added.
* // By default this is true only for the PIXI.Ticker.shared instance.
* ticker.autoStart = false;
* // FYI, call this to ensure the ticker is stopped. It should be stopped
* // if you have not attempted to render anything yet.
* ticker.stop();
* // Call this when you are ready for a running shared ticker.
* ticker.start();
*
* @example
* // You may use the shared ticker to render...
* let renderer = PIXI.autoDetectRenderer();
* let stage = new PIXI.Container();
* document.body.appendChild(renderer.view);
* ticker.add(function (time) {
* renderer.render(stage);
* });
*
* @example
* // Or you can just update it manually.
* ticker.autoStart = false;
* ticker.stop();
* function animate(time) {
* ticker.update(time);
* renderer.render(stage);
* requestAnimationFrame(animate);
* }
* animate(performance.now());
*
* @member {PIXI.Ticker}
* @static
*/
staticAccessors.shared.get = function ()
{
if (!Ticker._shared)
{
var shared = Ticker._shared = new Ticker();
shared.autoStart = true;
shared._protected = true;
}
return Ticker._shared;
};
/**
* The system ticker instance used by {@link PIXI.interaction.InteractionManager} and by
* {@link PIXI.BasePrepare} for core timing functionality that shouldn't usually need to be paused,
* unlike the `shared` ticker which drives visual animations and rendering which may want to be paused.
*
* The property {@link PIXI.Ticker#autoStart} is set to `true` for this instance.
*
* @member {PIXI.Ticker}
* @static
*/
staticAccessors.system.get = function ()
{
if (!Ticker._system)
{
var system = Ticker._system = new Ticker();
system.autoStart = true;
system._protected = true;
}
return Ticker._system;
};
Object.defineProperties( Ticker.prototype, prototypeAccessors );
Object.defineProperties( Ticker, staticAccessors );
/**
* Middleware for for Application Ticker.

@@ -867,100 +744,91 @@ *

*/
var TickerPlugin = function TickerPlugin () {};
TickerPlugin.init = function init (options)
{
var this$1 = this;
// Set default
options = Object.assign({
autoStart: true,
sharedTicker: false,
}, options);
// Create ticker setter
Object.defineProperty(this, 'ticker',
{
set: function set(ticker)
{
if (this._ticker)
{
var TickerPlugin = /** @class */ (function () {
function TickerPlugin() {
}
/**
* Initialize the plugin with scope of application instance
*
* @static
* @private
* @param {object} [options] - See application options
*/
TickerPlugin.init = function (options) {
var _this = this;
// Set default
options = Object.assign({
autoStart: true,
sharedTicker: false,
}, options);
// Create ticker setter
Object.defineProperty(this, 'ticker', {
set: function (ticker) {
if (this._ticker) {
this._ticker.remove(this.render, this);
}
this._ticker = ticker;
if (ticker)
{
ticker.add(this.render, this, UPDATE_PRIORITY.LOW);
if (ticker) {
ticker.add(this.render, this, exports.UPDATE_PRIORITY.LOW);
}
},
get: function get()
{
get: function () {
return this._ticker;
},
});
/**
* Convenience method for stopping the render.
*
* @method PIXI.Application#stop
*/
this.stop = function () {
this$1._ticker.stop();
/**
* Convenience method for stopping the render.
*
* @method PIXI.Application#stop
*/
this.stop = function () {
_this._ticker.stop();
};
/**
* Convenience method for starting the render.
*
* @method PIXI.Application#start
*/
this.start = function () {
_this._ticker.start();
};
/**
* Internal reference to the ticker.
*
* @type {PIXI.Ticker}
* @name _ticker
* @memberof PIXI.Application#
* @private
*/
this._ticker = null;
/**
* Ticker for doing render updates.
*
* @type {PIXI.Ticker}
* @name ticker
* @memberof PIXI.Application#
* @default PIXI.Ticker.shared
*/
this.ticker = options.sharedTicker ? Ticker.shared : new Ticker();
// Start the rendering
if (options.autoStart) {
this.start();
}
};
/**
* Convenience method for starting the render.
* Clean up the ticker, scoped to application.
*
* @method PIXI.Application#start
* @static
* @private
*/
this.start = function () {
this$1._ticker.start();
TickerPlugin.destroy = function () {
if (this._ticker) {
var oldTicker = this._ticker;
this.ticker = null;
oldTicker.destroy();
}
};
return TickerPlugin;
}());
/**
* Internal reference to the ticker.
*
* @type {PIXI.Ticker}
* @name _ticker
* @memberof PIXI.Application#
* @private
*/
this._ticker = null;
/**
* Ticker for doing render updates.
*
* @type {PIXI.Ticker}
* @name ticker
* @memberof PIXI.Application#
* @default PIXI.Ticker.shared
*/
this.ticker = options.sharedTicker ? Ticker.shared : new Ticker();
// Start the rendering
if (options.autoStart)
{
this.start();
}
};
/**
* Clean up the ticker, scoped to application.
*
* @static
* @private
*/
TickerPlugin.destroy = function destroy ()
{
if (this._ticker)
{
var oldTicker = this._ticker;
this.ticker = null;
oldTicker.destroy();
}
};
exports.Ticker = Ticker;
exports.TickerPlugin = TickerPlugin;
exports.UPDATE_PRIORITY = UPDATE_PRIORITY;
//# sourceMappingURL=ticker.js.map
{
"name": "@pixi/ticker",
"version": "5.1.3",
"version": "5.2.0",
"main": "lib/ticker.js",

@@ -27,5 +27,5 @@ "module": "lib/ticker.es.js",

"dependencies": {
"@pixi/settings": "^5.1.3"
"@pixi/settings": "^5.2.0"
},
"gitHead": "ee5ed4ddb3e1967f7e8a88c952479d51368fd3e2"
"gitHead": "aaf96b460582b83a1fa73037ef2dd69dd9e84415"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc