diff --git a/src/core/Application.js b/src/core/Application.js index 1a0eaf2..bc730db 100644 --- a/src/core/Application.js +++ b/src/core/Application.js @@ -54,16 +54,21 @@ */ this.ticker = new Ticker(); - this.ticker.add(() => - { - this.renderer.render(this.stage); - }); + this.ticker.add(this.render, this); // Start the rendering this.start(); } /** + * Render the current stage. + */ + render() + { + this.renderer.render(this.stage); + } + + /** * Convenience method for stopping the render. */ stop() @@ -88,4 +93,21 @@ { return this.renderer.view; } + + /** + * Destroy and don't use after this. + * @param {Boolean} [removeView=false] Automatically remove canvas from DOM. + */ + destroy(removeView) + { + this.stop(); + this.ticker.remove(this.render, this); + this.ticker = null; + + this.stage.destroy(); + this.stage = null; + + this.renderer.destroy(removeView); + this.renderer = null; + } } diff --git a/src/core/Application.js b/src/core/Application.js index 1a0eaf2..bc730db 100644 --- a/src/core/Application.js +++ b/src/core/Application.js @@ -54,16 +54,21 @@ */ this.ticker = new Ticker(); - this.ticker.add(() => - { - this.renderer.render(this.stage); - }); + this.ticker.add(this.render, this); // Start the rendering this.start(); } /** + * Render the current stage. + */ + render() + { + this.renderer.render(this.stage); + } + + /** * Convenience method for stopping the render. */ stop() @@ -88,4 +93,21 @@ { return this.renderer.view; } + + /** + * Destroy and don't use after this. + * @param {Boolean} [removeView=false] Automatically remove canvas from DOM. + */ + destroy(removeView) + { + this.stop(); + this.ticker.remove(this.render, this); + this.ticker = null; + + this.stage.destroy(); + this.stage = null; + + this.renderer.destroy(removeView); + this.renderer = null; + } } diff --git a/test/core/Application.js b/test/core/Application.js new file mode 100644 index 0000000..aa726b0 --- /dev/null +++ b/test/core/Application.js @@ -0,0 +1,20 @@ +'use strict'; + +describe('PIXI.Application', function () +{ + it('should generate application', function (done) + { + expect(PIXI.Application).to.be.a.function; + const app = new PIXI.Application(); + + expect(app.stage).to.be.instanceof(PIXI.Container); + expect(app.ticker).to.be.instanceof(PIXI.ticker.Ticker); + expect(app.renderer).to.be.ok; + + app.ticker.addOnce(() => + { + app.destroy(); + done(); + }); + }); +}); diff --git a/src/core/Application.js b/src/core/Application.js index 1a0eaf2..bc730db 100644 --- a/src/core/Application.js +++ b/src/core/Application.js @@ -54,16 +54,21 @@ */ this.ticker = new Ticker(); - this.ticker.add(() => - { - this.renderer.render(this.stage); - }); + this.ticker.add(this.render, this); // Start the rendering this.start(); } /** + * Render the current stage. + */ + render() + { + this.renderer.render(this.stage); + } + + /** * Convenience method for stopping the render. */ stop() @@ -88,4 +93,21 @@ { return this.renderer.view; } + + /** + * Destroy and don't use after this. + * @param {Boolean} [removeView=false] Automatically remove canvas from DOM. + */ + destroy(removeView) + { + this.stop(); + this.ticker.remove(this.render, this); + this.ticker = null; + + this.stage.destroy(); + this.stage = null; + + this.renderer.destroy(removeView); + this.renderer = null; + } } diff --git a/test/core/Application.js b/test/core/Application.js new file mode 100644 index 0000000..aa726b0 --- /dev/null +++ b/test/core/Application.js @@ -0,0 +1,20 @@ +'use strict'; + +describe('PIXI.Application', function () +{ + it('should generate application', function (done) + { + expect(PIXI.Application).to.be.a.function; + const app = new PIXI.Application(); + + expect(app.stage).to.be.instanceof(PIXI.Container); + expect(app.ticker).to.be.instanceof(PIXI.ticker.Ticker); + expect(app.renderer).to.be.ok; + + app.ticker.addOnce(() => + { + app.destroy(); + done(); + }); + }); +}); diff --git a/test/core/index.js b/test/core/index.js index 405a557..2a056a2 100755 --- a/test/core/index.js +++ b/test/core/index.js @@ -1,5 +1,6 @@ 'use strict'; +require('./Application'); require('./TransformStatic'); require('./Bounds'); require('./Container');