diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 24c7e64..64ed31d 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -544,3 +544,12 @@ renderer.maskManager.popMask(renderer); } }; + +/** + * Destroys the container + * + */ +Container.prototype.destroy = function () +{ + this.children = null; +}; diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 24c7e64..64ed31d 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -544,3 +544,12 @@ renderer.maskManager.popMask(renderer); } }; + +/** + * Destroys the container + * + */ +Container.prototype.destroy = function () +{ + this.children = null; +}; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index d4dcb35..048b84a 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -439,3 +439,24 @@ return renderTexture; }; + +/** + * Base destroy method for generic display objects + * + */ +DisplayObject.prototype.destroy = function () +{ + + this.position = null; + this.scale = null; + this.pivot = null; + + this._bounds = null; + this._currentBounds = null; + this._mask = null; + + this.worldTransform = null; + this.filterArea = null; + + this.listeners = null; +}; diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 24c7e64..64ed31d 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -544,3 +544,12 @@ renderer.maskManager.popMask(renderer); } }; + +/** + * Destroys the container + * + */ +Container.prototype.destroy = function () +{ + this.children = null; +}; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index d4dcb35..048b84a 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -439,3 +439,24 @@ return renderTexture; }; + +/** + * Base destroy method for generic display objects + * + */ +DisplayObject.prototype.destroy = function () +{ + + this.position = null; + this.scale = null; + this.pivot = null; + + this._bounds = null; + this._currentBounds = null; + this._mask = null; + + this.worldTransform = null; + this.filterArea = null; + + this.listeners = null; +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 3d544d9..7fa2218 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -93,27 +93,6 @@ this.texture = texture || Texture.EMPTY; } -/** - * Destroys this sprite and optionally its texture - * - * @param destroyTexture {boolean} Should it destroy the current texture of the sprite as well - * @param destroyBaseTexture {boolean} Should it destroy the base texture of the sprite as well - */ -Sprite.prototype.destroy = function (destroyTexture, destroyBaseTexture) -{ - Container.prototype.destroy.call(this); - - this.anchor = null; - - if (destroyTexture) - { - this._texture.destroy(destroyBaseTexture); - } - - this._texture = null; - this.shader = null; -}; - // constructor Sprite.prototype = Object.create(Container.prototype); Sprite.prototype.constructor = Sprite; @@ -504,6 +483,27 @@ } }; +/** + * Destroys this sprite and optionally its texture + * + * @param destroyTexture {boolean} Should it destroy the current texture of the sprite as well + * @param destroyBaseTexture {boolean} Should it destroy the base texture of the sprite as well + */ +Sprite.prototype.destroy = function (destroyTexture, destroyBaseTexture) +{ + Container.prototype.destroy.call(this); + + this.anchor = null; + + if (destroyTexture) + { + this._texture.destroy(destroyBaseTexture); + } + + this._texture = null; + this.shader = null; +}; + // some helper functions.. /** diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 24c7e64..64ed31d 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -544,3 +544,12 @@ renderer.maskManager.popMask(renderer); } }; + +/** + * Destroys the container + * + */ +Container.prototype.destroy = function () +{ + this.children = null; +}; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index d4dcb35..048b84a 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -439,3 +439,24 @@ return renderTexture; }; + +/** + * Base destroy method for generic display objects + * + */ +DisplayObject.prototype.destroy = function () +{ + + this.position = null; + this.scale = null; + this.pivot = null; + + this._bounds = null; + this._currentBounds = null; + this._mask = null; + + this.worldTransform = null; + this.filterArea = null; + + this.listeners = null; +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 3d544d9..7fa2218 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -93,27 +93,6 @@ this.texture = texture || Texture.EMPTY; } -/** - * Destroys this sprite and optionally its texture - * - * @param destroyTexture {boolean} Should it destroy the current texture of the sprite as well - * @param destroyBaseTexture {boolean} Should it destroy the base texture of the sprite as well - */ -Sprite.prototype.destroy = function (destroyTexture, destroyBaseTexture) -{ - Container.prototype.destroy.call(this); - - this.anchor = null; - - if (destroyTexture) - { - this._texture.destroy(destroyBaseTexture); - } - - this._texture = null; - this.shader = null; -}; - // constructor Sprite.prototype = Object.create(Container.prototype); Sprite.prototype.constructor = Sprite; @@ -504,6 +483,27 @@ } }; +/** + * Destroys this sprite and optionally its texture + * + * @param destroyTexture {boolean} Should it destroy the current texture of the sprite as well + * @param destroyBaseTexture {boolean} Should it destroy the base texture of the sprite as well + */ +Sprite.prototype.destroy = function (destroyTexture, destroyBaseTexture) +{ + Container.prototype.destroy.call(this); + + this.anchor = null; + + if (destroyTexture) + { + this._texture.destroy(destroyBaseTexture); + } + + this._texture = null; + this.shader = null; +}; + // some helper functions.. /** 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/display/Container.js b/src/core/display/Container.js index 24c7e64..64ed31d 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -544,3 +544,12 @@ renderer.maskManager.popMask(renderer); } }; + +/** + * Destroys the container + * + */ +Container.prototype.destroy = function () +{ + this.children = null; +}; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index d4dcb35..048b84a 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -439,3 +439,24 @@ return renderTexture; }; + +/** + * Base destroy method for generic display objects + * + */ +DisplayObject.prototype.destroy = function () +{ + + this.position = null; + this.scale = null; + this.pivot = null; + + this._bounds = null; + this._currentBounds = null; + this._mask = null; + + this.worldTransform = null; + this.filterArea = null; + + this.listeners = null; +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 3d544d9..7fa2218 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -93,27 +93,6 @@ this.texture = texture || Texture.EMPTY; } -/** - * Destroys this sprite and optionally its texture - * - * @param destroyTexture {boolean} Should it destroy the current texture of the sprite as well - * @param destroyBaseTexture {boolean} Should it destroy the base texture of the sprite as well - */ -Sprite.prototype.destroy = function (destroyTexture, destroyBaseTexture) -{ - Container.prototype.destroy.call(this); - - this.anchor = null; - - if (destroyTexture) - { - this._texture.destroy(destroyBaseTexture); - } - - this._texture = null; - this.shader = null; -}; - // constructor Sprite.prototype = Object.create(Container.prototype); Sprite.prototype.constructor = Sprite; @@ -504,6 +483,27 @@ } }; +/** + * Destroys this sprite and optionally its texture + * + * @param destroyTexture {boolean} Should it destroy the current texture of the sprite as well + * @param destroyBaseTexture {boolean} Should it destroy the base texture of the sprite as well + */ +Sprite.prototype.destroy = function (destroyTexture, destroyBaseTexture) +{ + Container.prototype.destroy.call(this); + + this.anchor = null; + + if (destroyTexture) + { + this._texture.destroy(destroyBaseTexture); + } + + this._texture = null; + this.shader = null; +}; + // some helper functions.. /** 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/index.js b/src/core/utils/index.js index 12026e6..5008c8e 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -8,7 +8,6 @@ _saidHello: false, RAFramePolyfill:require('./requestAnimationFramePolyfill'), - Ticker: require('./Ticker'), EventData: require('./EventData'), eventTarget: require('./eventTarget'), pluginTarget: require('./pluginTarget'), diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 24c7e64..64ed31d 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -544,3 +544,12 @@ renderer.maskManager.popMask(renderer); } }; + +/** + * Destroys the container + * + */ +Container.prototype.destroy = function () +{ + this.children = null; +}; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index d4dcb35..048b84a 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -439,3 +439,24 @@ return renderTexture; }; + +/** + * Base destroy method for generic display objects + * + */ +DisplayObject.prototype.destroy = function () +{ + + this.position = null; + this.scale = null; + this.pivot = null; + + this._bounds = null; + this._currentBounds = null; + this._mask = null; + + this.worldTransform = null; + this.filterArea = null; + + this.listeners = null; +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 3d544d9..7fa2218 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -93,27 +93,6 @@ this.texture = texture || Texture.EMPTY; } -/** - * Destroys this sprite and optionally its texture - * - * @param destroyTexture {boolean} Should it destroy the current texture of the sprite as well - * @param destroyBaseTexture {boolean} Should it destroy the base texture of the sprite as well - */ -Sprite.prototype.destroy = function (destroyTexture, destroyBaseTexture) -{ - Container.prototype.destroy.call(this); - - this.anchor = null; - - if (destroyTexture) - { - this._texture.destroy(destroyBaseTexture); - } - - this._texture = null; - this.shader = null; -}; - // constructor Sprite.prototype = Object.create(Container.prototype); Sprite.prototype.constructor = Sprite; @@ -504,6 +483,27 @@ } }; +/** + * Destroys this sprite and optionally its texture + * + * @param destroyTexture {boolean} Should it destroy the current texture of the sprite as well + * @param destroyBaseTexture {boolean} Should it destroy the base texture of the sprite as well + */ +Sprite.prototype.destroy = function (destroyTexture, destroyBaseTexture) +{ + Container.prototype.destroy.call(this); + + this.anchor = null; + + if (destroyTexture) + { + this._texture.destroy(destroyBaseTexture); + } + + this._texture = null; + this.shader = null; +}; + // some helper functions.. /** 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/index.js b/src/core/utils/index.js index 12026e6..5008c8e 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -8,7 +8,6 @@ _saidHello: false, RAFramePolyfill:require('./requestAnimationFramePolyfill'), - Ticker: require('./Ticker'), EventData: require('./EventData'), eventTarget: require('./eventTarget'), pluginTarget: require('./pluginTarget'), diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 40f5212..9db67ff 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,5 +1,5 @@ -var core = require('../core'), - utils = require('../core/utils'); +var core = require('../core'), + Ticker = require('./Ticker'); /** * A MovieClip is a simple way to display an animation depicted by a list of textures. @@ -138,7 +138,7 @@ } this.playing = false; - utils.Ticker.off('tick', this._updateBound); + Ticker.off('tick', this._updateBound); }; /** @@ -153,7 +153,7 @@ } this.playing = true; - utils.Ticker.on('tick', this._updateBound); + Ticker.on('tick', this._updateBound); }; /** diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 24c7e64..64ed31d 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -544,3 +544,12 @@ renderer.maskManager.popMask(renderer); } }; + +/** + * Destroys the container + * + */ +Container.prototype.destroy = function () +{ + this.children = null; +}; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index d4dcb35..048b84a 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -439,3 +439,24 @@ return renderTexture; }; + +/** + * Base destroy method for generic display objects + * + */ +DisplayObject.prototype.destroy = function () +{ + + this.position = null; + this.scale = null; + this.pivot = null; + + this._bounds = null; + this._currentBounds = null; + this._mask = null; + + this.worldTransform = null; + this.filterArea = null; + + this.listeners = null; +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 3d544d9..7fa2218 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -93,27 +93,6 @@ this.texture = texture || Texture.EMPTY; } -/** - * Destroys this sprite and optionally its texture - * - * @param destroyTexture {boolean} Should it destroy the current texture of the sprite as well - * @param destroyBaseTexture {boolean} Should it destroy the base texture of the sprite as well - */ -Sprite.prototype.destroy = function (destroyTexture, destroyBaseTexture) -{ - Container.prototype.destroy.call(this); - - this.anchor = null; - - if (destroyTexture) - { - this._texture.destroy(destroyBaseTexture); - } - - this._texture = null; - this.shader = null; -}; - // constructor Sprite.prototype = Object.create(Container.prototype); Sprite.prototype.constructor = Sprite; @@ -504,6 +483,27 @@ } }; +/** + * Destroys this sprite and optionally its texture + * + * @param destroyTexture {boolean} Should it destroy the current texture of the sprite as well + * @param destroyBaseTexture {boolean} Should it destroy the base texture of the sprite as well + */ +Sprite.prototype.destroy = function (destroyTexture, destroyBaseTexture) +{ + Container.prototype.destroy.call(this); + + this.anchor = null; + + if (destroyTexture) + { + this._texture.destroy(destroyBaseTexture); + } + + this._texture = null; + this.shader = null; +}; + // some helper functions.. /** 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/index.js b/src/core/utils/index.js index 12026e6..5008c8e 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -8,7 +8,6 @@ _saidHello: false, RAFramePolyfill:require('./requestAnimationFramePolyfill'), - Ticker: require('./Ticker'), EventData: require('./EventData'), eventTarget: require('./eventTarget'), pluginTarget: require('./pluginTarget'), diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 40f5212..9db67ff 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,5 +1,5 @@ -var core = require('../core'), - utils = require('../core/utils'); +var core = require('../core'), + Ticker = require('./Ticker'); /** * A MovieClip is a simple way to display an animation depicted by a list of textures. @@ -138,7 +138,7 @@ } this.playing = false; - utils.Ticker.off('tick', this._updateBound); + Ticker.off('tick', this._updateBound); }; /** @@ -153,7 +153,7 @@ } this.playing = true; - utils.Ticker.on('tick', this._updateBound); + Ticker.on('tick', this._updateBound); }; /** diff --git a/src/extras/Ticker.js b/src/extras/Ticker.js new file mode 100644 index 0000000..d8ddfcf --- /dev/null +++ b/src/extras/Ticker.js @@ -0,0 +1,123 @@ +var eventTarget = require('../core/utils/eventTarget'), + EventData = require('../core/utils/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(); diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 24c7e64..64ed31d 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -544,3 +544,12 @@ renderer.maskManager.popMask(renderer); } }; + +/** + * Destroys the container + * + */ +Container.prototype.destroy = function () +{ + this.children = null; +}; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index d4dcb35..048b84a 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -439,3 +439,24 @@ return renderTexture; }; + +/** + * Base destroy method for generic display objects + * + */ +DisplayObject.prototype.destroy = function () +{ + + this.position = null; + this.scale = null; + this.pivot = null; + + this._bounds = null; + this._currentBounds = null; + this._mask = null; + + this.worldTransform = null; + this.filterArea = null; + + this.listeners = null; +}; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 3d544d9..7fa2218 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -93,27 +93,6 @@ this.texture = texture || Texture.EMPTY; } -/** - * Destroys this sprite and optionally its texture - * - * @param destroyTexture {boolean} Should it destroy the current texture of the sprite as well - * @param destroyBaseTexture {boolean} Should it destroy the base texture of the sprite as well - */ -Sprite.prototype.destroy = function (destroyTexture, destroyBaseTexture) -{ - Container.prototype.destroy.call(this); - - this.anchor = null; - - if (destroyTexture) - { - this._texture.destroy(destroyBaseTexture); - } - - this._texture = null; - this.shader = null; -}; - // constructor Sprite.prototype = Object.create(Container.prototype); Sprite.prototype.constructor = Sprite; @@ -504,6 +483,27 @@ } }; +/** + * Destroys this sprite and optionally its texture + * + * @param destroyTexture {boolean} Should it destroy the current texture of the sprite as well + * @param destroyBaseTexture {boolean} Should it destroy the base texture of the sprite as well + */ +Sprite.prototype.destroy = function (destroyTexture, destroyBaseTexture) +{ + Container.prototype.destroy.call(this); + + this.anchor = null; + + if (destroyTexture) + { + this._texture.destroy(destroyBaseTexture); + } + + this._texture = null; + this.shader = null; +}; + // some helper functions.. /** 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/index.js b/src/core/utils/index.js index 12026e6..5008c8e 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -8,7 +8,6 @@ _saidHello: false, RAFramePolyfill:require('./requestAnimationFramePolyfill'), - Ticker: require('./Ticker'), EventData: require('./EventData'), eventTarget: require('./eventTarget'), pluginTarget: require('./pluginTarget'), diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 40f5212..9db67ff 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,5 +1,5 @@ -var core = require('../core'), - utils = require('../core/utils'); +var core = require('../core'), + Ticker = require('./Ticker'); /** * A MovieClip is a simple way to display an animation depicted by a list of textures. @@ -138,7 +138,7 @@ } this.playing = false; - utils.Ticker.off('tick', this._updateBound); + Ticker.off('tick', this._updateBound); }; /** @@ -153,7 +153,7 @@ } this.playing = true; - utils.Ticker.on('tick', this._updateBound); + Ticker.on('tick', this._updateBound); }; /** diff --git a/src/extras/Ticker.js b/src/extras/Ticker.js new file mode 100644 index 0000000..d8ddfcf --- /dev/null +++ b/src/extras/Ticker.js @@ -0,0 +1,123 @@ +var eventTarget = require('../core/utils/eventTarget'), + EventData = require('../core/utils/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(); diff --git a/src/extras/index.js b/src/extras/index.js index 6f14e0d..29f3ac8 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -9,6 +9,7 @@ * @namespace PIXI.extras */ module.exports = { + Ticker: require('./Ticker'), MovieClip: require('./MovieClip'), TilingSprite: require('./TilingSprite'), cacheAsBitmap: require('./cacheAsBitmap'),