diff --git a/src/core/utils/Ticker.js b/src/core/utils/Ticker.js deleted file mode 100644 index ae797c4..0000000 --- a/src/core/utils/Ticker.js +++ /dev/null @@ -1,99 +0,0 @@ -var eventTarget = require('./eventTarget'), - EventData = require('./EventData'); - -/** - * A Ticker class that runs the main update loop that other objects listen to - * - * @class - * @memberof PIXI.utils - */ -var Ticker = function() -{ - this.updateBind = this.update.bind(this); - - /** - * Whether or not this ticker runs - * - * @member {boolean} - */ - this.active = false; - this.eventData = new EventData( this, 'tick', { deltaTime:1 } ); - - /** - * The deltaTime - * - * @member {number} - */ - this.deltaTime = 1; - - /** - * The time between two frames - * - * @member {number} - */ - this.timeElapsed = 0; - this.lastTime = 0; - - this.speed = 1; - - // auto start ticking! - this.start(); -}; - -eventTarget.mixin(Ticker.prototype); - - -Ticker.prototype.start = function() -{ - if(this.active) - { - return; - } - - this.active = true; - requestAnimationFrame(this.updateBind); -}; - - -Ticker.prototype.stop = function() -{ - if(!this.active) - { - return; - } - - this.active = false; -}; - -Ticker.prototype.update = function() -{ - if(this.active) - { - requestAnimationFrame(this.updateBind); - - var currentTime = new Date().getTime(); - var timeElapsed = currentTime - this.lastTime; - - // cap the time! - if(timeElapsed > 100) - { - timeElapsed = 100; - } - - this.deltaTime = (timeElapsed * 0.06); - - this.deltaTime *= this.speed; - - // 60 ---> 1 - // 30 ---> 2 - - this.eventData.data.deltaTime = this.deltaTime; - - this.emit( 'tick', this.eventData ); - - this.lastTime = currentTime; - } - -}; - -module.exports = new Ticker(); diff --git a/src/core/utils/Ticker.js b/src/core/utils/Ticker.js deleted file mode 100644 index ae797c4..0000000 --- a/src/core/utils/Ticker.js +++ /dev/null @@ -1,99 +0,0 @@ -var eventTarget = require('./eventTarget'), - EventData = require('./EventData'); - -/** - * A Ticker class that runs the main update loop that other objects listen to - * - * @class - * @memberof PIXI.utils - */ -var Ticker = function() -{ - this.updateBind = this.update.bind(this); - - /** - * Whether or not this ticker runs - * - * @member {boolean} - */ - this.active = false; - this.eventData = new EventData( this, 'tick', { deltaTime:1 } ); - - /** - * The deltaTime - * - * @member {number} - */ - this.deltaTime = 1; - - /** - * The time between two frames - * - * @member {number} - */ - this.timeElapsed = 0; - this.lastTime = 0; - - this.speed = 1; - - // auto start ticking! - this.start(); -}; - -eventTarget.mixin(Ticker.prototype); - - -Ticker.prototype.start = function() -{ - if(this.active) - { - return; - } - - this.active = true; - requestAnimationFrame(this.updateBind); -}; - - -Ticker.prototype.stop = function() -{ - if(!this.active) - { - return; - } - - this.active = false; -}; - -Ticker.prototype.update = function() -{ - if(this.active) - { - requestAnimationFrame(this.updateBind); - - var currentTime = new Date().getTime(); - var timeElapsed = currentTime - this.lastTime; - - // cap the time! - if(timeElapsed > 100) - { - timeElapsed = 100; - } - - this.deltaTime = (timeElapsed * 0.06); - - this.deltaTime *= this.speed; - - // 60 ---> 1 - // 30 ---> 2 - - this.eventData.data.deltaTime = this.deltaTime; - - this.emit( 'tick', this.eventData ); - - this.lastTime = currentTime; - } - -}; - -module.exports = new Ticker(); diff --git a/src/extras/Ticker.js b/src/extras/Ticker.js new file mode 100644 index 0000000..5ff7d18 --- /dev/null +++ b/src/extras/Ticker.js @@ -0,0 +1,123 @@ +var eventTarget = require('./eventTarget'), + EventData = require('./EventData'); + +/** + * A Ticker class that runs an update loop that other objects listen to + * + * @class + * @memberof PIXI.extras + */ +var Ticker = function() +{ + this.updateBind = this.update.bind(this); + + /** + * Whether or not this ticker runs + * + * @member {boolean} + */ + this.active = false; + + /** + * the event data for this ticker to dispatch the tick event + * + * @member {EventData} + */ + this.eventData = new EventData( this, 'tick', { deltaTime:1 } ); + + /** + * The deltaTime + * + * @member {number} + */ + this.deltaTime = 1; + + /** + * The time between two frames + * + * @member {number} + */ + this.timeElapsed = 0; + + /** + * The time at the last frame + * + * @member {number} + */ + this.lastTime = 0; + + /** + * The speed + * + * @member {number} + */ + this.speed = 1; + + // auto start ticking! + this.start(); +}; + +eventTarget.mixin(Ticker.prototype); + +/** + * Starts the ticker, automatically called by the constructor + * + */ +Ticker.prototype.start = function() +{ + if(this.active) + { + return; + } + + this.active = true; + requestAnimationFrame(this.updateBind); +}; + +/** + * Stops the ticker + * + */ +Ticker.prototype.stop = function() +{ + if(!this.active) + { + return; + } + + this.active = false; +}; + +/** + * The update loop, fires the 'tick' event + * + */ +Ticker.prototype.update = function() +{ + if(this.active) + { + requestAnimationFrame(this.updateBind); + + var currentTime = new Date().getTime(); + var timeElapsed = currentTime - this.lastTime; + + // cap the time! + if(timeElapsed > 100) + { + timeElapsed = 100; + } + + this.deltaTime = (timeElapsed * 0.06); + + this.deltaTime *= this.speed; + + this.eventData.data.deltaTime = this.deltaTime; + + this.emit( 'tick', this.eventData ); + + this.lastTime = currentTime; + } + +}; + +module.exports = new Ticker();