diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 20f2b99..35ada4d 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -17,6 +17,14 @@ Object.defineProperties(DisplayObject.prototype, { + + /** + * Set this to true if you want this display object to be cached as a bitmap. + * This basically takes a snap shot of the display object as it is at that moment. It can provide a performance benefit for complex static displayObjects. + * To remove simply set this property to 'null' + * @member + * @memberof DisplayObject# + */ cacheAsBitmap: { get: function () { @@ -60,12 +68,16 @@ this.getBounds = this._originalGetBounds; this.updateTransform = this._originalUpdateTransform; - this.containsPoint = this._originalContainesPoint; + this.containsPoint = this._originalContainsPoint; } } } }); - +/** +* Renders a cached version of the sprite with WebGL +* @param renderer {WebGLRenderer} the WebGL renderer +* @private +*/ DisplayObject.prototype._renderCachedWebGL = function(renderer) { this._initCachedDisplayObject( renderer ); @@ -76,6 +88,11 @@ renderer.plugins.sprite.render( this._cachedSprite ); }; +/** +* Prepares the WebGL renderer to cache the sprite +* @param renderer {WebGLRenderer} the WebGL renderer +* @private +*/ DisplayObject.prototype._initCachedDisplayObject = function( renderer ) { if(this._cachedSprite) @@ -83,6 +100,7 @@ return; } + // first we flush anything left in the renderer (otherwise it would get rendered to the cached texture) renderer.currentRenderer.flush(); //this.filters= []; @@ -117,7 +135,7 @@ this.renderWebGL = this._renderCachedWebGL; this.updateTransform = this.displayObjectUpdateTransform; - this.getBounds = this._getCahcedBounds; + this.getBounds = this._getCachedBounds; // create our cached sprite @@ -130,7 +148,11 @@ this.containsPoint = this._cachedSprite.containsPoint.bind(this._cachedSprite); }; - +/** +* Renders a cached version of the sprite with canvas +* @param renderer {CanvasRenderer} the Canvas renderer +* @private +*/ DisplayObject.prototype._renderCachedCanvas = function(renderer) { this._initCachedDisplayObjectCanvas( renderer ); @@ -141,6 +163,11 @@ }; //TODO this can be the same as the webGL verison.. will need to do a little tweaking first though.. +/** +* Prepares the Canvas renderer to cache the sprite +* @param renderer {CanvasRenderer} the Canvas renderer +* @private +*/ DisplayObject.prototype._initCachedDisplayObjectCanvas = function( renderer ) { if(this._cachedSprite) @@ -171,7 +198,7 @@ this.renderCanvas = this._renderCachedCanvas; this.updateTransform = this.displayObjectUpdateTransform; - this.getBounds = this._getCahcedBounds; + this.getBounds = this._getCachedBounds; // create our cached sprite @@ -182,13 +209,23 @@ this.hitTest = this._cachedSprite.hitTest.bind(this._cachedSprite); }; -DisplayObject.prototype._getCahcedBounds = function() +/** +* Calculates the bounds of the cached sprite +* +* @private +*/ +DisplayObject.prototype._getCachedBounds = function() { this._cachedSprite._currentBounds = null; return this._cachedSprite.getBounds(); }; +/** +* Destroys the cached sprite. +* +* @private +*/ DisplayObject.prototype._destroyCachedDisplayObject = function() { this._cachedSprite._texture.destroy(); diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 20f2b99..35ada4d 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -17,6 +17,14 @@ Object.defineProperties(DisplayObject.prototype, { + + /** + * Set this to true if you want this display object to be cached as a bitmap. + * This basically takes a snap shot of the display object as it is at that moment. It can provide a performance benefit for complex static displayObjects. + * To remove simply set this property to 'null' + * @member + * @memberof DisplayObject# + */ cacheAsBitmap: { get: function () { @@ -60,12 +68,16 @@ this.getBounds = this._originalGetBounds; this.updateTransform = this._originalUpdateTransform; - this.containsPoint = this._originalContainesPoint; + this.containsPoint = this._originalContainsPoint; } } } }); - +/** +* Renders a cached version of the sprite with WebGL +* @param renderer {WebGLRenderer} the WebGL renderer +* @private +*/ DisplayObject.prototype._renderCachedWebGL = function(renderer) { this._initCachedDisplayObject( renderer ); @@ -76,6 +88,11 @@ renderer.plugins.sprite.render( this._cachedSprite ); }; +/** +* Prepares the WebGL renderer to cache the sprite +* @param renderer {WebGLRenderer} the WebGL renderer +* @private +*/ DisplayObject.prototype._initCachedDisplayObject = function( renderer ) { if(this._cachedSprite) @@ -83,6 +100,7 @@ return; } + // first we flush anything left in the renderer (otherwise it would get rendered to the cached texture) renderer.currentRenderer.flush(); //this.filters= []; @@ -117,7 +135,7 @@ this.renderWebGL = this._renderCachedWebGL; this.updateTransform = this.displayObjectUpdateTransform; - this.getBounds = this._getCahcedBounds; + this.getBounds = this._getCachedBounds; // create our cached sprite @@ -130,7 +148,11 @@ this.containsPoint = this._cachedSprite.containsPoint.bind(this._cachedSprite); }; - +/** +* Renders a cached version of the sprite with canvas +* @param renderer {CanvasRenderer} the Canvas renderer +* @private +*/ DisplayObject.prototype._renderCachedCanvas = function(renderer) { this._initCachedDisplayObjectCanvas( renderer ); @@ -141,6 +163,11 @@ }; //TODO this can be the same as the webGL verison.. will need to do a little tweaking first though.. +/** +* Prepares the Canvas renderer to cache the sprite +* @param renderer {CanvasRenderer} the Canvas renderer +* @private +*/ DisplayObject.prototype._initCachedDisplayObjectCanvas = function( renderer ) { if(this._cachedSprite) @@ -171,7 +198,7 @@ this.renderCanvas = this._renderCachedCanvas; this.updateTransform = this.displayObjectUpdateTransform; - this.getBounds = this._getCahcedBounds; + this.getBounds = this._getCachedBounds; // create our cached sprite @@ -182,13 +209,23 @@ this.hitTest = this._cachedSprite.hitTest.bind(this._cachedSprite); }; -DisplayObject.prototype._getCahcedBounds = function() +/** +* Calculates the bounds of the cached sprite +* +* @private +*/ +DisplayObject.prototype._getCachedBounds = function() { this._cachedSprite._currentBounds = null; return this._cachedSprite.getBounds(); }; +/** +* Destroys the cached sprite. +* +* @private +*/ DisplayObject.prototype._destroyCachedDisplayObject = function() { this._cachedSprite._texture.destroy(); diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index 1c8b400..28ba7ee 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -1,5 +1,6 @@ var Resource = require('resource-loader').Resource, - core = require('../core'); + core = require('../core'), + text = require('../text'); module.exports = function () { @@ -84,6 +85,8 @@ resource.bitmapFont = data; + text.BitmapText.fonts[data.font] = data; + next(); }); }; diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 20f2b99..35ada4d 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -17,6 +17,14 @@ Object.defineProperties(DisplayObject.prototype, { + + /** + * Set this to true if you want this display object to be cached as a bitmap. + * This basically takes a snap shot of the display object as it is at that moment. It can provide a performance benefit for complex static displayObjects. + * To remove simply set this property to 'null' + * @member + * @memberof DisplayObject# + */ cacheAsBitmap: { get: function () { @@ -60,12 +68,16 @@ this.getBounds = this._originalGetBounds; this.updateTransform = this._originalUpdateTransform; - this.containsPoint = this._originalContainesPoint; + this.containsPoint = this._originalContainsPoint; } } } }); - +/** +* Renders a cached version of the sprite with WebGL +* @param renderer {WebGLRenderer} the WebGL renderer +* @private +*/ DisplayObject.prototype._renderCachedWebGL = function(renderer) { this._initCachedDisplayObject( renderer ); @@ -76,6 +88,11 @@ renderer.plugins.sprite.render( this._cachedSprite ); }; +/** +* Prepares the WebGL renderer to cache the sprite +* @param renderer {WebGLRenderer} the WebGL renderer +* @private +*/ DisplayObject.prototype._initCachedDisplayObject = function( renderer ) { if(this._cachedSprite) @@ -83,6 +100,7 @@ return; } + // first we flush anything left in the renderer (otherwise it would get rendered to the cached texture) renderer.currentRenderer.flush(); //this.filters= []; @@ -117,7 +135,7 @@ this.renderWebGL = this._renderCachedWebGL; this.updateTransform = this.displayObjectUpdateTransform; - this.getBounds = this._getCahcedBounds; + this.getBounds = this._getCachedBounds; // create our cached sprite @@ -130,7 +148,11 @@ this.containsPoint = this._cachedSprite.containsPoint.bind(this._cachedSprite); }; - +/** +* Renders a cached version of the sprite with canvas +* @param renderer {CanvasRenderer} the Canvas renderer +* @private +*/ DisplayObject.prototype._renderCachedCanvas = function(renderer) { this._initCachedDisplayObjectCanvas( renderer ); @@ -141,6 +163,11 @@ }; //TODO this can be the same as the webGL verison.. will need to do a little tweaking first though.. +/** +* Prepares the Canvas renderer to cache the sprite +* @param renderer {CanvasRenderer} the Canvas renderer +* @private +*/ DisplayObject.prototype._initCachedDisplayObjectCanvas = function( renderer ) { if(this._cachedSprite) @@ -171,7 +198,7 @@ this.renderCanvas = this._renderCachedCanvas; this.updateTransform = this.displayObjectUpdateTransform; - this.getBounds = this._getCahcedBounds; + this.getBounds = this._getCachedBounds; // create our cached sprite @@ -182,13 +209,23 @@ this.hitTest = this._cachedSprite.hitTest.bind(this._cachedSprite); }; -DisplayObject.prototype._getCahcedBounds = function() +/** +* Calculates the bounds of the cached sprite +* +* @private +*/ +DisplayObject.prototype._getCachedBounds = function() { this._cachedSprite._currentBounds = null; return this._cachedSprite.getBounds(); }; +/** +* Destroys the cached sprite. +* +* @private +*/ DisplayObject.prototype._destroyCachedDisplayObject = function() { this._cachedSprite._texture.destroy(); diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index 1c8b400..28ba7ee 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -1,5 +1,6 @@ var Resource = require('resource-loader').Resource, - core = require('../core'); + core = require('../core'), + text = require('../text'); module.exports = function () { @@ -84,6 +85,8 @@ resource.bitmapFont = data; + text.BitmapText.fonts[data.font] = data; + next(); }); }; diff --git a/src/text/BitmapText.js b/src/text/BitmapText.js index 2ffd2b4..996bdc5 100644 --- a/src/text/BitmapText.js +++ b/src/text/BitmapText.js @@ -10,7 +10,7 @@ * // in this case the font is in a file called 'desyrel.fnt' * var bitmapText = new PIXI.BitmapText("text using a fancy font!", {font: "35px Desyrel", align: "right"}); * ``` - * + * * * http://www.angelcode.com/products/bmfont/ for windows or * http://www.bmglyph.com/ for mac. @@ -203,7 +203,7 @@ */ BitmapText.prototype.updateText = function () { - var data = BitmapText.fonts[this.fontName]; + var data = BitmapText.fonts[this._style.fontName]; var pos = new core.math.Point(); var prevCharCode = null; var chars = []; @@ -275,11 +275,11 @@ { var alignOffset = 0; - if (this.style.align === 'right') + if (this._style.align === 'right') { alignOffset = maxLineWidth - lineWidths[i]; } - else if (this.style.align === 'center') + else if (this._style.align === 'center') { alignOffset = (maxLineWidth - lineWidths[i]) / 2; } @@ -341,7 +341,7 @@ this.containerUpdateTransform(); }; -BitmapText.prototype.setText = function () +BitmapText.prototype.setText = function () { window.console.warn(" setText is now deprecated, please use the text property, e.g : myBitmapText.text = 'my text'; "); };