diff --git a/src/core/text/Text.js b/src/core/text/Text.js index ab57fc8..901ce43 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -5,6 +5,11 @@ CONST = require('../const'), TextStyle = require('./TextStyle'); + var defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true + }; /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -740,15 +745,23 @@ /** * Destroys this text object. + * Note* Unlike a Sprite, a Text object will automatically destroy its baseTexture and texture as + * the majorety of the time the texture will not be shared with any other Sprites. * * @param [options] {object|boolean} Options parameter. A boolean will act as if all options have been set to that value * @param [options.children=false] {boolean} if set to true, all the children will have their destroy * method called as well. 'options' will be passed on to those calls. - * @param [options.texture=false] {boolean} Should it destroy the current texture of the sprite as well - * @param [options.baseTexture=false] {boolean} Should it destroy the base texture of the sprite as well + * @param [options.texture=true] {boolean} Should it destroy the current texture of the sprite as well + * @param [options.baseTexture=true] {boolean} Should it destroy the base texture of the sprite as well */ Text.prototype.destroy = function (options) { + if (typeof options === 'boolean') { + options = { children: options }; + } + + options = Object.assign({}, defaultDestroyOptions, options); + Sprite.prototype.destroy.call(this, options); // make sure to reset the the context and canvas.. dont want this hanging around in memory! diff --git a/src/core/text/Text.js b/src/core/text/Text.js index ab57fc8..901ce43 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -5,6 +5,11 @@ CONST = require('../const'), TextStyle = require('./TextStyle'); + var defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true + }; /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -740,15 +745,23 @@ /** * Destroys this text object. + * Note* Unlike a Sprite, a Text object will automatically destroy its baseTexture and texture as + * the majorety of the time the texture will not be shared with any other Sprites. * * @param [options] {object|boolean} Options parameter. A boolean will act as if all options have been set to that value * @param [options.children=false] {boolean} if set to true, all the children will have their destroy * method called as well. 'options' will be passed on to those calls. - * @param [options.texture=false] {boolean} Should it destroy the current texture of the sprite as well - * @param [options.baseTexture=false] {boolean} Should it destroy the base texture of the sprite as well + * @param [options.texture=true] {boolean} Should it destroy the current texture of the sprite as well + * @param [options.baseTexture=true] {boolean} Should it destroy the base texture of the sprite as well */ Text.prototype.destroy = function (options) { + if (typeof options === 'boolean') { + options = { children: options }; + } + + options = Object.assign({}, defaultDestroyOptions, options); + Sprite.prototype.destroy.call(this, options); // make sure to reset the the context and canvas.. dont want this hanging around in memory! diff --git a/test/core/Text.js b/test/core/Text.js index 4564c06..a2c510c 100644 --- a/test/core/Text.js +++ b/test/core/Text.js @@ -26,7 +26,7 @@ expect(child.transform).to.equal(null); }); - it('should accept boolean correctly', function () { + it('should accept options correctly', function () { var text = new PIXI.Text("foo"), child = new PIXI.DisplayObject(); @@ -47,7 +47,7 @@ text.addChild(child); text.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true, baseTexture:true}); }); }); });