diff --git a/src/pixi/textures/BaseTexture.js b/src/pixi/textures/BaseTexture.js index 71763c6..4535f3e 100644 --- a/src/pixi/textures/BaseTexture.js +++ b/src/pixi/textures/BaseTexture.js @@ -7,7 +7,7 @@ PIXI.BaseTextureCacheIdGenerator = 0; /** - * A texture stores the information that represents an image. All textures have a base texture + * A texture stores the information that represents an image. All textures have a base texture. * * @class BaseTexture * @uses EventTarget @@ -45,6 +45,7 @@ /** * The scale mode to apply when scaling this texture + * * @property scaleMode * @type PIXI.scaleModes * @default PIXI.scaleModes.LINEAR @@ -52,7 +53,7 @@ this.scaleMode = scaleMode || PIXI.scaleModes.DEFAULT; /** - * [read-only] Describes if the base texture has loaded or not + * [read-only] Set to true once the base texture has loaded * * @property hasLoaded * @type Boolean @@ -61,34 +62,42 @@ this.hasLoaded = false; /** - * The source that is loaded to create the texture + * The image source that is used to create the texture. * * @property source * @type Image */ this.source = source; - //TODO will be used for futer pixi 1.5... this._UID = PIXI._UID++; /** - * Controls if RGB channels should be premultiplied by Alpha (WebGL only) + * Controls if RGB channels should be pre-multiplied by Alpha (WebGL only) * - * @property + * @property premultipliedAlpha * @type Boolean - * @default TRUE - */ + * @default true + */ this.premultipliedAlpha = true; - - - // used for webGL + + /** + * @property _glTextures + * @type Array + * @private + */ this._glTextures = []; + // used for webGL texture updating... // TODO - this needs to be addressed - this._dirty = [true, true, true, true]; + /** + * @property _dirty + * @type Array + * @private + */ + this._dirty = [true, true, true, true]; if(!source)return; @@ -101,8 +110,8 @@ } else { - var scope = this; + this.source.onload = function() { scope.hasLoaded = true; @@ -114,19 +123,29 @@ // add it to somewhere... scope.dispatchEvent( { type: 'loaded', content: scope } ); }; + this.source.onerror = function() { scope.dispatchEvent( { type: 'error', content: scope } ); }; } + /** + * @property imageUrl + * @type String + */ this.imageUrl = null; + + /** + * @property _powerOf2 + * @type Boolean + * @private + */ this._powerOf2 = false; - - }; PIXI.BaseTexture.prototype.constructor = PIXI.BaseTexture; + PIXI.EventTarget.mixin(PIXI.BaseTexture.prototype); /** @@ -177,6 +196,11 @@ this.source.src = newSrc; }; +/** + * Sets all glTextures to be dirty. + * + * @method dirty + */ PIXI.BaseTexture.prototype.dirty = function() { for (var i = 0; i < this._glTextures.length; i++) @@ -186,8 +210,8 @@ }; /** - * Helper function that returns a base texture based on an image url - * If the image is not in the base texture cache it will be created and loaded + * Helper function that creates a base texture from the given image url. + * If the image is not in the base texture cache it will be created and loaded. * * @static * @method fromImage @@ -204,7 +228,6 @@ if(!baseTexture) { - // new Image() breaks tex loading in some versions of Chrome. // See https://code.google.com/p/chromium/issues/detail?id=238071 var image = new Image();//document.createElement('img'); @@ -229,8 +252,7 @@ }; /** - * Helper function that returns a base texture based on a canvas element - * If the image is not in the base texture cache it will be created and loaded + * Helper function that creates a base texture from the given canvas element. * * @static * @method fromCanvas @@ -255,5 +277,3 @@ return baseTexture; }; - - diff --git a/src/pixi/textures/BaseTexture.js b/src/pixi/textures/BaseTexture.js index 71763c6..4535f3e 100644 --- a/src/pixi/textures/BaseTexture.js +++ b/src/pixi/textures/BaseTexture.js @@ -7,7 +7,7 @@ PIXI.BaseTextureCacheIdGenerator = 0; /** - * A texture stores the information that represents an image. All textures have a base texture + * A texture stores the information that represents an image. All textures have a base texture. * * @class BaseTexture * @uses EventTarget @@ -45,6 +45,7 @@ /** * The scale mode to apply when scaling this texture + * * @property scaleMode * @type PIXI.scaleModes * @default PIXI.scaleModes.LINEAR @@ -52,7 +53,7 @@ this.scaleMode = scaleMode || PIXI.scaleModes.DEFAULT; /** - * [read-only] Describes if the base texture has loaded or not + * [read-only] Set to true once the base texture has loaded * * @property hasLoaded * @type Boolean @@ -61,34 +62,42 @@ this.hasLoaded = false; /** - * The source that is loaded to create the texture + * The image source that is used to create the texture. * * @property source * @type Image */ this.source = source; - //TODO will be used for futer pixi 1.5... this._UID = PIXI._UID++; /** - * Controls if RGB channels should be premultiplied by Alpha (WebGL only) + * Controls if RGB channels should be pre-multiplied by Alpha (WebGL only) * - * @property + * @property premultipliedAlpha * @type Boolean - * @default TRUE - */ + * @default true + */ this.premultipliedAlpha = true; - - - // used for webGL + + /** + * @property _glTextures + * @type Array + * @private + */ this._glTextures = []; + // used for webGL texture updating... // TODO - this needs to be addressed - this._dirty = [true, true, true, true]; + /** + * @property _dirty + * @type Array + * @private + */ + this._dirty = [true, true, true, true]; if(!source)return; @@ -101,8 +110,8 @@ } else { - var scope = this; + this.source.onload = function() { scope.hasLoaded = true; @@ -114,19 +123,29 @@ // add it to somewhere... scope.dispatchEvent( { type: 'loaded', content: scope } ); }; + this.source.onerror = function() { scope.dispatchEvent( { type: 'error', content: scope } ); }; } + /** + * @property imageUrl + * @type String + */ this.imageUrl = null; + + /** + * @property _powerOf2 + * @type Boolean + * @private + */ this._powerOf2 = false; - - }; PIXI.BaseTexture.prototype.constructor = PIXI.BaseTexture; + PIXI.EventTarget.mixin(PIXI.BaseTexture.prototype); /** @@ -177,6 +196,11 @@ this.source.src = newSrc; }; +/** + * Sets all glTextures to be dirty. + * + * @method dirty + */ PIXI.BaseTexture.prototype.dirty = function() { for (var i = 0; i < this._glTextures.length; i++) @@ -186,8 +210,8 @@ }; /** - * Helper function that returns a base texture based on an image url - * If the image is not in the base texture cache it will be created and loaded + * Helper function that creates a base texture from the given image url. + * If the image is not in the base texture cache it will be created and loaded. * * @static * @method fromImage @@ -204,7 +228,6 @@ if(!baseTexture) { - // new Image() breaks tex loading in some versions of Chrome. // See https://code.google.com/p/chromium/issues/detail?id=238071 var image = new Image();//document.createElement('img'); @@ -229,8 +252,7 @@ }; /** - * Helper function that returns a base texture based on a canvas element - * If the image is not in the base texture cache it will be created and loaded + * Helper function that creates a base texture from the given canvas element. * * @static * @method fromCanvas @@ -255,5 +277,3 @@ return baseTexture; }; - - diff --git a/src/pixi/textures/RenderTexture.js b/src/pixi/textures/RenderTexture.js index a38283c..2f02ff3 100644 --- a/src/pixi/textures/RenderTexture.js +++ b/src/pixi/textures/RenderTexture.js @@ -3,12 +3,11 @@ */ /** - * A RenderTexture is a special texture that allows any pixi displayObject to be rendered to it. + * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. * - * __Hint__: All DisplayObjects (exmpl. Sprites) that render on RenderTexture should be preloaded. - * Otherwise black rectangles will be drawn instead. + * __Hint__: All DisplayObjects (i.e. Sprites) that render to a RenderTexture should be preloaded otherwise black rectangles will be drawn instead. * - * RenderTexture takes snapshot of DisplayObject passed to render method. If DisplayObject is passed to render method, position and rotation of it will be ignored. For example: + * A RenderTexture takes a snapshot of any Display Object given to its render method. The position and rotation of the given Display Objects is ignored. For example: * * var renderTexture = new PIXI.RenderTexture(800, 600); * var sprite = PIXI.Sprite.fromImage("spinObj_01.png"); @@ -18,7 +17,7 @@ * sprite.anchor.y = 0.5; * renderTexture.render(sprite); * - * Sprite in this case will be rendered to 0,0 position. To render this sprite at center DisplayObjectContainer should be used: + * The Sprite in this case will be rendered to a position of 0,0. To render this sprite at its actual position a DisplayObjectContainer should be used: * * var doc = new PIXI.DisplayObjectContainer(); * doc.addChild(sprite); @@ -29,6 +28,7 @@ * @constructor * @param width {Number} The width of the render texture * @param height {Number} The height of the render texture + * @param renderer {CanvasRenderer|WebGLRenderer} The renderer used for this RenderTexture * @param scaleMode {Number} Should be one of the PIXI.scaleMode consts * @param resolution {Number} The resolution of the texture being generated */ @@ -96,7 +96,12 @@ new PIXI.Rectangle(0, 0, this.width, this.height) ); - // each render texture can only belong to one renderer at the moment if its webGL + /** + * The renderer this RenderTexture uses. A RenderTexture can only belong to one renderer at the moment if its webGL. + * + * @property renderer + * @type CanvasRenderer|WebGLRenderer + */ this.renderer = renderer || PIXI.defaultRenderer; if(this.renderer.type === PIXI.WEBGL_RENDERER) @@ -117,6 +122,10 @@ this.baseTexture.source = this.textureBuffer.canvas; } + /** + * @property valid + * @type Boolean + */ this.valid = true; this._updateUvs(); @@ -126,7 +135,7 @@ PIXI.RenderTexture.prototype.constructor = PIXI.RenderTexture; /** - * Resize the RenderTexture. + * Resizes the RenderTexture. * * @method resize * @param width {Number} The width to resize to. @@ -139,7 +148,6 @@ this.valid = (width > 0 && height > 0); - this.width = this.frame.width = this.crop.width = width; this.height = this.frame.height = this.crop.height = height; @@ -182,7 +190,8 @@ * * @method renderWebGL * @param displayObject {DisplayObject} The display object to render this texture on - * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn + * @param [matrix] {Matrix} Optional matrix to apply to the display object before rendering. + * @param [clear] {Boolean} If true the texture will be cleared before the displayObject is drawn * @private */ PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, matrix, clear) @@ -230,7 +239,8 @@ * * @method renderCanvas * @param displayObject {DisplayObject} The display object to render this texture on - * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn + * @param [matrix] {Matrix} Optional matrix to apply to the display object before rendering. + * @param [clear] {Boolean} If true the texture will be cleared before the displayObject is drawn * @private */ PIXI.RenderTexture.prototype.renderCanvas = function(displayObject, matrix, clear) @@ -266,6 +276,7 @@ * Will return a HTML Image of the texture * * @method getImage + * @return {HTMLImage} */ PIXI.RenderTexture.prototype.getImage = function() { @@ -275,15 +286,22 @@ }; /** - * Will return a a base64 string of the texture + * Will return a a base64 encoded string of this texture. It works by calling RenderTexture.getCanvas and then running toDataURL on that. * - * @method getImage + * @method getBase64 + * @return {String} A base64 encoded string of the texture. */ PIXI.RenderTexture.prototype.getBase64 = function() { return this.getCanvas().toDataURL(); }; +/** + * Creates a Canvas element, renders this RenderTexture to it and then returns it. + * + * @method getCanvas + * @return {HTMLCanvasElement} A Canvas element with the texture rendered on. + */ PIXI.RenderTexture.prototype.getCanvas = function() { if (this.renderer.type === PIXI.WEBGL_RENDERER) @@ -322,4 +340,3 @@ }; PIXI.RenderTexture.tempMatrix = new PIXI.Matrix(); - diff --git a/src/pixi/textures/BaseTexture.js b/src/pixi/textures/BaseTexture.js index 71763c6..4535f3e 100644 --- a/src/pixi/textures/BaseTexture.js +++ b/src/pixi/textures/BaseTexture.js @@ -7,7 +7,7 @@ PIXI.BaseTextureCacheIdGenerator = 0; /** - * A texture stores the information that represents an image. All textures have a base texture + * A texture stores the information that represents an image. All textures have a base texture. * * @class BaseTexture * @uses EventTarget @@ -45,6 +45,7 @@ /** * The scale mode to apply when scaling this texture + * * @property scaleMode * @type PIXI.scaleModes * @default PIXI.scaleModes.LINEAR @@ -52,7 +53,7 @@ this.scaleMode = scaleMode || PIXI.scaleModes.DEFAULT; /** - * [read-only] Describes if the base texture has loaded or not + * [read-only] Set to true once the base texture has loaded * * @property hasLoaded * @type Boolean @@ -61,34 +62,42 @@ this.hasLoaded = false; /** - * The source that is loaded to create the texture + * The image source that is used to create the texture. * * @property source * @type Image */ this.source = source; - //TODO will be used for futer pixi 1.5... this._UID = PIXI._UID++; /** - * Controls if RGB channels should be premultiplied by Alpha (WebGL only) + * Controls if RGB channels should be pre-multiplied by Alpha (WebGL only) * - * @property + * @property premultipliedAlpha * @type Boolean - * @default TRUE - */ + * @default true + */ this.premultipliedAlpha = true; - - - // used for webGL + + /** + * @property _glTextures + * @type Array + * @private + */ this._glTextures = []; + // used for webGL texture updating... // TODO - this needs to be addressed - this._dirty = [true, true, true, true]; + /** + * @property _dirty + * @type Array + * @private + */ + this._dirty = [true, true, true, true]; if(!source)return; @@ -101,8 +110,8 @@ } else { - var scope = this; + this.source.onload = function() { scope.hasLoaded = true; @@ -114,19 +123,29 @@ // add it to somewhere... scope.dispatchEvent( { type: 'loaded', content: scope } ); }; + this.source.onerror = function() { scope.dispatchEvent( { type: 'error', content: scope } ); }; } + /** + * @property imageUrl + * @type String + */ this.imageUrl = null; + + /** + * @property _powerOf2 + * @type Boolean + * @private + */ this._powerOf2 = false; - - }; PIXI.BaseTexture.prototype.constructor = PIXI.BaseTexture; + PIXI.EventTarget.mixin(PIXI.BaseTexture.prototype); /** @@ -177,6 +196,11 @@ this.source.src = newSrc; }; +/** + * Sets all glTextures to be dirty. + * + * @method dirty + */ PIXI.BaseTexture.prototype.dirty = function() { for (var i = 0; i < this._glTextures.length; i++) @@ -186,8 +210,8 @@ }; /** - * Helper function that returns a base texture based on an image url - * If the image is not in the base texture cache it will be created and loaded + * Helper function that creates a base texture from the given image url. + * If the image is not in the base texture cache it will be created and loaded. * * @static * @method fromImage @@ -204,7 +228,6 @@ if(!baseTexture) { - // new Image() breaks tex loading in some versions of Chrome. // See https://code.google.com/p/chromium/issues/detail?id=238071 var image = new Image();//document.createElement('img'); @@ -229,8 +252,7 @@ }; /** - * Helper function that returns a base texture based on a canvas element - * If the image is not in the base texture cache it will be created and loaded + * Helper function that creates a base texture from the given canvas element. * * @static * @method fromCanvas @@ -255,5 +277,3 @@ return baseTexture; }; - - diff --git a/src/pixi/textures/RenderTexture.js b/src/pixi/textures/RenderTexture.js index a38283c..2f02ff3 100644 --- a/src/pixi/textures/RenderTexture.js +++ b/src/pixi/textures/RenderTexture.js @@ -3,12 +3,11 @@ */ /** - * A RenderTexture is a special texture that allows any pixi displayObject to be rendered to it. + * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. * - * __Hint__: All DisplayObjects (exmpl. Sprites) that render on RenderTexture should be preloaded. - * Otherwise black rectangles will be drawn instead. + * __Hint__: All DisplayObjects (i.e. Sprites) that render to a RenderTexture should be preloaded otherwise black rectangles will be drawn instead. * - * RenderTexture takes snapshot of DisplayObject passed to render method. If DisplayObject is passed to render method, position and rotation of it will be ignored. For example: + * A RenderTexture takes a snapshot of any Display Object given to its render method. The position and rotation of the given Display Objects is ignored. For example: * * var renderTexture = new PIXI.RenderTexture(800, 600); * var sprite = PIXI.Sprite.fromImage("spinObj_01.png"); @@ -18,7 +17,7 @@ * sprite.anchor.y = 0.5; * renderTexture.render(sprite); * - * Sprite in this case will be rendered to 0,0 position. To render this sprite at center DisplayObjectContainer should be used: + * The Sprite in this case will be rendered to a position of 0,0. To render this sprite at its actual position a DisplayObjectContainer should be used: * * var doc = new PIXI.DisplayObjectContainer(); * doc.addChild(sprite); @@ -29,6 +28,7 @@ * @constructor * @param width {Number} The width of the render texture * @param height {Number} The height of the render texture + * @param renderer {CanvasRenderer|WebGLRenderer} The renderer used for this RenderTexture * @param scaleMode {Number} Should be one of the PIXI.scaleMode consts * @param resolution {Number} The resolution of the texture being generated */ @@ -96,7 +96,12 @@ new PIXI.Rectangle(0, 0, this.width, this.height) ); - // each render texture can only belong to one renderer at the moment if its webGL + /** + * The renderer this RenderTexture uses. A RenderTexture can only belong to one renderer at the moment if its webGL. + * + * @property renderer + * @type CanvasRenderer|WebGLRenderer + */ this.renderer = renderer || PIXI.defaultRenderer; if(this.renderer.type === PIXI.WEBGL_RENDERER) @@ -117,6 +122,10 @@ this.baseTexture.source = this.textureBuffer.canvas; } + /** + * @property valid + * @type Boolean + */ this.valid = true; this._updateUvs(); @@ -126,7 +135,7 @@ PIXI.RenderTexture.prototype.constructor = PIXI.RenderTexture; /** - * Resize the RenderTexture. + * Resizes the RenderTexture. * * @method resize * @param width {Number} The width to resize to. @@ -139,7 +148,6 @@ this.valid = (width > 0 && height > 0); - this.width = this.frame.width = this.crop.width = width; this.height = this.frame.height = this.crop.height = height; @@ -182,7 +190,8 @@ * * @method renderWebGL * @param displayObject {DisplayObject} The display object to render this texture on - * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn + * @param [matrix] {Matrix} Optional matrix to apply to the display object before rendering. + * @param [clear] {Boolean} If true the texture will be cleared before the displayObject is drawn * @private */ PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, matrix, clear) @@ -230,7 +239,8 @@ * * @method renderCanvas * @param displayObject {DisplayObject} The display object to render this texture on - * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn + * @param [matrix] {Matrix} Optional matrix to apply to the display object before rendering. + * @param [clear] {Boolean} If true the texture will be cleared before the displayObject is drawn * @private */ PIXI.RenderTexture.prototype.renderCanvas = function(displayObject, matrix, clear) @@ -266,6 +276,7 @@ * Will return a HTML Image of the texture * * @method getImage + * @return {HTMLImage} */ PIXI.RenderTexture.prototype.getImage = function() { @@ -275,15 +286,22 @@ }; /** - * Will return a a base64 string of the texture + * Will return a a base64 encoded string of this texture. It works by calling RenderTexture.getCanvas and then running toDataURL on that. * - * @method getImage + * @method getBase64 + * @return {String} A base64 encoded string of the texture. */ PIXI.RenderTexture.prototype.getBase64 = function() { return this.getCanvas().toDataURL(); }; +/** + * Creates a Canvas element, renders this RenderTexture to it and then returns it. + * + * @method getCanvas + * @return {HTMLCanvasElement} A Canvas element with the texture rendered on. + */ PIXI.RenderTexture.prototype.getCanvas = function() { if (this.renderer.type === PIXI.WEBGL_RENDERER) @@ -322,4 +340,3 @@ }; PIXI.RenderTexture.tempMatrix = new PIXI.Matrix(); - diff --git a/src/pixi/textures/Texture.js b/src/pixi/textures/Texture.js index 6b40986..02b6513 100644 --- a/src/pixi/textures/Texture.js +++ b/src/pixi/textures/Texture.js @@ -9,7 +9,7 @@ /** * A texture stores the information that represents an image or part of an image. It cannot be added - * to the display list directly. To do this use PIXI.Sprite. If no frame is provided then the whole image is used + * to the display list directly. Instead use it as the texture for a PIXI.Sprite. If no frame is provided then the whole image is used. * * @class Texture * @uses EventTarget @@ -57,7 +57,7 @@ this.frame = frame; /** - * The trim point + * The texture trim data. * * @property trim * @type Rectangle @@ -65,7 +65,7 @@ this.trim = trim; /** - * This will let the renderer know if the texture is valid. If its not then it cannot be rendered. + * This will let the renderer know if the texture is valid. If it's not then it cannot be rendered. * * @property valid * @type Boolean @@ -83,9 +83,9 @@ /** * The WebGL UV data cache. * - * @private * @property _uvs * @type Object + * @private */ this._uvs = null; @@ -132,7 +132,6 @@ * Called when the base texture is loaded * * @method onBaseTextureLoaded - * @param event * @private */ PIXI.Texture.prototype.onBaseTextureLoaded = function() @@ -201,7 +200,7 @@ /** * Updates the internal WebGL UV cache. * - * @method _updateWebGLuvs + * @method _updateUvs * @private */ PIXI.Texture.prototype._updateUvs = function() @@ -223,12 +222,11 @@ this._uvs.x3 = frame.x / tw; this._uvs.y3 = (frame.y + frame.height) / th; - }; /** - * Helper function that returns a texture based on an image url - * If the image is not in the texture cache it will be created and loaded + * Helper function that creates a Texture object from the given image url. + * If the image is not in the texture cache it will be created and loaded. * * @static * @method fromImage @@ -251,8 +249,8 @@ }; /** - * Helper function that returns a texture based on a frame id - * If the frame id is not in the texture cache an error will be thrown + * Helper function that returns a Texture objected based on the given frame id. + * If the frame id is not in the texture cache an error will be thrown. * * @static * @method fromFrame @@ -267,8 +265,7 @@ }; /** - * Helper function that returns a texture based on a canvas element - * If the canvas is not in the texture cache it will be created and loaded + * Helper function that creates a new a Texture based on the given canvas element. * * @static * @method fromCanvas @@ -284,14 +281,13 @@ }; - /** - * Adds a texture to the textureCache. + * Adds a texture to the global PIXI.TextureCache. This cache is shared across the whole PIXI object. * * @static * @method addTextureToCache - * @param texture {Texture} - * @param id {String} the id that the texture will be stored against. + * @param texture {Texture} The Texture to add to the cache. + * @param id {String} The id that the texture will be stored against. */ PIXI.Texture.addTextureToCache = function(texture, id) { @@ -299,12 +295,12 @@ }; /** - * Remove a texture from the textureCache. + * Remove a texture from the global PIXI.TextureCache. * * @static * @method removeTextureFromCache - * @param id {String} the id of the texture to be removed - * @return {Texture} the texture that was removed + * @param id {String} The id of the texture to be removed + * @return {Texture} The texture that was removed */ PIXI.Texture.removeTextureFromCache = function(id) { @@ -314,7 +310,6 @@ return texture; }; - PIXI.TextureUvs = function() { this.x0 = 0;