diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 7b7421a..a07e0d5 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -20,8 +20,6 @@ { Container.call(this); - this.renderable = true; - /** * The alpha value used when filling the Graphics object. * diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 7b7421a..a07e0d5 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -20,8 +20,6 @@ { Container.call(this); - this.renderable = true; - /** * The alpha value used when filling the Graphics object. * diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 1c131bb..39a9754 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -363,7 +363,7 @@ // empty all the old gl textures as they are useless now for (var key in utils.BaseTextureCache) { - utils.BaseTextureCache[key]._glTextures = {}; + utils.BaseTextureCache[key]._glTextures.length = 0; } }; diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 7b7421a..a07e0d5 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -20,8 +20,6 @@ { Container.call(this); - this.renderable = true; - /** * The alpha value used when filling the Graphics object. * diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 1c131bb..39a9754 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -363,7 +363,7 @@ // empty all the old gl textures as they are useless now for (var key in utils.BaseTextureCache) { - utils.BaseTextureCache[key]._glTextures = {}; + utils.BaseTextureCache[key]._glTextures.length = 0; } }; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index f246832..0105965 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -80,8 +80,6 @@ */ this.shader = null; - this.renderable = true; - this.cachedTint = 0xFFFFFF; // call texture setter @@ -199,6 +197,12 @@ { this.scale.y = this._height / this.texture.frame.height; } + + if (this.texture.rotation) { + this.rotation = this.texture.rotation; + // this.pivot.x = this.texture.spritePivot.x; + // this.pivot.y = this.texture.spritePivot.y; + } }; Sprite.prototype._renderWebGL = function (renderer) diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 7b7421a..a07e0d5 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -20,8 +20,6 @@ { Container.call(this); - this.renderable = true; - /** * The alpha value used when filling the Graphics object. * diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 1c131bb..39a9754 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -363,7 +363,7 @@ // empty all the old gl textures as they are useless now for (var key in utils.BaseTextureCache) { - utils.BaseTextureCache[key]._glTextures = {}; + utils.BaseTextureCache[key]._glTextures.length = 0; } }; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index f246832..0105965 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -80,8 +80,6 @@ */ this.shader = null; - this.renderable = true; - this.cachedTint = 0xFFFFFF; // call texture setter @@ -199,6 +197,12 @@ { this.scale.y = this._height / this.texture.frame.height; } + + if (this.texture.rotation) { + this.rotation = this.texture.rotation; + // this.pivot.x = this.texture.spritePivot.x; + // this.pivot.y = this.texture.spritePivot.y; + } }; Sprite.prototype._renderWebGL = function (renderer) diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 684eee3..fe0533c 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -113,15 +113,7 @@ * @member {object} * @private */ - this._glTextures = {}; - - /** - * Does the texture on the GPU need to be updated? - * - * @member {boolean} - * @private - */ - this._needsUpdate = false; + this._glTextures = []; // if no source passed don't try to load if (source) @@ -149,23 +141,14 @@ utils.eventTarget.mixin(BaseTexture.prototype); -Object.defineProperties(BaseTexture.prototype, { - needsUpdate: { - get: function () - { - return this._needsUpdate; - }, - set: function (val) - { - this._needsUpdate = val; - - if (val) - { - this.emit('update', this); - } - } - } -}); +/** + * Updates the texture on all the webgl renderers. + * + * @fires update + */ +BaseTexture.prototype.update = function () { + this.emit('update', this); +}; /** * Load a source. @@ -294,7 +277,7 @@ this.width = this.source.naturalWidth || this.source.width; this.height = this.source.naturalHeight || this.source.height; - this.needsUpdate = true; + this.update(); }; /** diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 7b7421a..a07e0d5 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -20,8 +20,6 @@ { Container.call(this); - this.renderable = true; - /** * The alpha value used when filling the Graphics object. * diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 1c131bb..39a9754 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -363,7 +363,7 @@ // empty all the old gl textures as they are useless now for (var key in utils.BaseTextureCache) { - utils.BaseTextureCache[key]._glTextures = {}; + utils.BaseTextureCache[key]._glTextures.length = 0; } }; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index f246832..0105965 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -80,8 +80,6 @@ */ this.shader = null; - this.renderable = true; - this.cachedTint = 0xFFFFFF; // call texture setter @@ -199,6 +197,12 @@ { this.scale.y = this._height / this.texture.frame.height; } + + if (this.texture.rotation) { + this.rotation = this.texture.rotation; + // this.pivot.x = this.texture.spritePivot.x; + // this.pivot.y = this.texture.spritePivot.y; + } }; Sprite.prototype._renderWebGL = function (renderer) diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 684eee3..fe0533c 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -113,15 +113,7 @@ * @member {object} * @private */ - this._glTextures = {}; - - /** - * Does the texture on the GPU need to be updated? - * - * @member {boolean} - * @private - */ - this._needsUpdate = false; + this._glTextures = []; // if no source passed don't try to load if (source) @@ -149,23 +141,14 @@ utils.eventTarget.mixin(BaseTexture.prototype); -Object.defineProperties(BaseTexture.prototype, { - needsUpdate: { - get: function () - { - return this._needsUpdate; - }, - set: function (val) - { - this._needsUpdate = val; - - if (val) - { - this.emit('update', this); - } - } - } -}); +/** + * Updates the texture on all the webgl renderers. + * + * @fires update + */ +BaseTexture.prototype.update = function () { + this.emit('update', this); +}; /** * Load a source. @@ -294,7 +277,7 @@ this.width = this.source.naturalWidth || this.source.width; this.height = this.source.naturalHeight || this.source.height; - this.needsUpdate = true; + this.update(); }; /** diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 0d132c6..8d7b26b 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -65,7 +65,6 @@ var baseTexture = new BaseTexture(); baseTexture.width = width * resolution; baseTexture.height = height * resolution; - baseTexture._glTextures = []; baseTexture.resolution = resolution; baseTexture.scaleMode = scaleMode || CONST.scaleModes.DEFAULT; baseTexture.hasLoaded = true; diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 7b7421a..a07e0d5 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -20,8 +20,6 @@ { Container.call(this); - this.renderable = true; - /** * The alpha value used when filling the Graphics object. * diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 1c131bb..39a9754 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -363,7 +363,7 @@ // empty all the old gl textures as they are useless now for (var key in utils.BaseTextureCache) { - utils.BaseTextureCache[key]._glTextures = {}; + utils.BaseTextureCache[key]._glTextures.length = 0; } }; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index f246832..0105965 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -80,8 +80,6 @@ */ this.shader = null; - this.renderable = true; - this.cachedTint = 0xFFFFFF; // call texture setter @@ -199,6 +197,12 @@ { this.scale.y = this._height / this.texture.frame.height; } + + if (this.texture.rotation) { + this.rotation = this.texture.rotation; + // this.pivot.x = this.texture.spritePivot.x; + // this.pivot.y = this.texture.spritePivot.y; + } }; Sprite.prototype._renderWebGL = function (renderer) diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 684eee3..fe0533c 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -113,15 +113,7 @@ * @member {object} * @private */ - this._glTextures = {}; - - /** - * Does the texture on the GPU need to be updated? - * - * @member {boolean} - * @private - */ - this._needsUpdate = false; + this._glTextures = []; // if no source passed don't try to load if (source) @@ -149,23 +141,14 @@ utils.eventTarget.mixin(BaseTexture.prototype); -Object.defineProperties(BaseTexture.prototype, { - needsUpdate: { - get: function () - { - return this._needsUpdate; - }, - set: function (val) - { - this._needsUpdate = val; - - if (val) - { - this.emit('update', this); - } - } - } -}); +/** + * Updates the texture on all the webgl renderers. + * + * @fires update + */ +BaseTexture.prototype.update = function () { + this.emit('update', this); +}; /** * Load a source. @@ -294,7 +277,7 @@ this.width = this.source.naturalWidth || this.source.width; this.height = this.source.naturalHeight || this.source.height; - this.needsUpdate = true; + this.update(); }; /** diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 0d132c6..8d7b26b 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -65,7 +65,6 @@ var baseTexture = new BaseTexture(); baseTexture.width = width * resolution; baseTexture.height = height * resolution; - baseTexture._glTextures = []; baseTexture.resolution = resolution; baseTexture.scaleMode = scaleMode || CONST.scaleModes.DEFAULT; baseTexture.hasLoaded = true; diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 949991d..3198a53 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -105,6 +105,20 @@ */ this.crop = crop || frame;//new math.Rectangle(0, 0, 1, 1); + /** + * The pivot point to used for a sprite this texture belongs to. + * + * @member {Point} + */ + this.spritePivot = new math.Point(); + + /** + * The rotation value of the texture, copied to a sprite when assigned to it. + * + * @member {number} + */ + this.rotation = 0; + if (baseTexture.hasLoaded) { if (this.noFrame) @@ -125,17 +139,6 @@ eventTarget.mixin(Texture.prototype); Object.defineProperties(Texture.prototype, { - needsUpdate: { - get: function () - { - return this.baseTexture.needsUpdate; - }, - set: function (val) - { - this.baseTexture.needsUpdate = val; - } - }, - frame: { get: function () { @@ -176,6 +179,15 @@ }); /** + * Updates this texture on the gpu. + * + */ +Texture.prototype.update = function () +{ + this.baseTexture.update(); +}; + +/** * Called when the base texture is loaded * * @private diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 7b7421a..a07e0d5 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -20,8 +20,6 @@ { Container.call(this); - this.renderable = true; - /** * The alpha value used when filling the Graphics object. * diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 1c131bb..39a9754 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -363,7 +363,7 @@ // empty all the old gl textures as they are useless now for (var key in utils.BaseTextureCache) { - utils.BaseTextureCache[key]._glTextures = {}; + utils.BaseTextureCache[key]._glTextures.length = 0; } }; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index f246832..0105965 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -80,8 +80,6 @@ */ this.shader = null; - this.renderable = true; - this.cachedTint = 0xFFFFFF; // call texture setter @@ -199,6 +197,12 @@ { this.scale.y = this._height / this.texture.frame.height; } + + if (this.texture.rotation) { + this.rotation = this.texture.rotation; + // this.pivot.x = this.texture.spritePivot.x; + // this.pivot.y = this.texture.spritePivot.y; + } }; Sprite.prototype._renderWebGL = function (renderer) diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 684eee3..fe0533c 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -113,15 +113,7 @@ * @member {object} * @private */ - this._glTextures = {}; - - /** - * Does the texture on the GPU need to be updated? - * - * @member {boolean} - * @private - */ - this._needsUpdate = false; + this._glTextures = []; // if no source passed don't try to load if (source) @@ -149,23 +141,14 @@ utils.eventTarget.mixin(BaseTexture.prototype); -Object.defineProperties(BaseTexture.prototype, { - needsUpdate: { - get: function () - { - return this._needsUpdate; - }, - set: function (val) - { - this._needsUpdate = val; - - if (val) - { - this.emit('update', this); - } - } - } -}); +/** + * Updates the texture on all the webgl renderers. + * + * @fires update + */ +BaseTexture.prototype.update = function () { + this.emit('update', this); +}; /** * Load a source. @@ -294,7 +277,7 @@ this.width = this.source.naturalWidth || this.source.width; this.height = this.source.naturalHeight || this.source.height; - this.needsUpdate = true; + this.update(); }; /** diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 0d132c6..8d7b26b 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -65,7 +65,6 @@ var baseTexture = new BaseTexture(); baseTexture.width = width * resolution; baseTexture.height = height * resolution; - baseTexture._glTextures = []; baseTexture.resolution = resolution; baseTexture.scaleMode = scaleMode || CONST.scaleModes.DEFAULT; baseTexture.hasLoaded = true; diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 949991d..3198a53 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -105,6 +105,20 @@ */ this.crop = crop || frame;//new math.Rectangle(0, 0, 1, 1); + /** + * The pivot point to used for a sprite this texture belongs to. + * + * @member {Point} + */ + this.spritePivot = new math.Point(); + + /** + * The rotation value of the texture, copied to a sprite when assigned to it. + * + * @member {number} + */ + this.rotation = 0; + if (baseTexture.hasLoaded) { if (this.noFrame) @@ -125,17 +139,6 @@ eventTarget.mixin(Texture.prototype); Object.defineProperties(Texture.prototype, { - needsUpdate: { - get: function () - { - return this.baseTexture.needsUpdate; - }, - set: function (val) - { - this.baseTexture.needsUpdate = val; - } - }, - frame: { get: function () { @@ -176,6 +179,15 @@ }); /** + * Updates this texture on the gpu. + * + */ +Texture.prototype.update = function () +{ + this.baseTexture.update(); +}; + +/** * Called when the base texture is loaded * * @private diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index f03ef64..fb658ec 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -56,7 +56,7 @@ if (this.autoUpdate) { window.requestAnimationFrame(this._boundOnUpdate); - this.needsUpdate = true; + this.update(); } }; diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 7b7421a..a07e0d5 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -20,8 +20,6 @@ { Container.call(this); - this.renderable = true; - /** * The alpha value used when filling the Graphics object. * diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 1c131bb..39a9754 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -363,7 +363,7 @@ // empty all the old gl textures as they are useless now for (var key in utils.BaseTextureCache) { - utils.BaseTextureCache[key]._glTextures = {}; + utils.BaseTextureCache[key]._glTextures.length = 0; } }; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index f246832..0105965 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -80,8 +80,6 @@ */ this.shader = null; - this.renderable = true; - this.cachedTint = 0xFFFFFF; // call texture setter @@ -199,6 +197,12 @@ { this.scale.y = this._height / this.texture.frame.height; } + + if (this.texture.rotation) { + this.rotation = this.texture.rotation; + // this.pivot.x = this.texture.spritePivot.x; + // this.pivot.y = this.texture.spritePivot.y; + } }; Sprite.prototype._renderWebGL = function (renderer) diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 684eee3..fe0533c 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -113,15 +113,7 @@ * @member {object} * @private */ - this._glTextures = {}; - - /** - * Does the texture on the GPU need to be updated? - * - * @member {boolean} - * @private - */ - this._needsUpdate = false; + this._glTextures = []; // if no source passed don't try to load if (source) @@ -149,23 +141,14 @@ utils.eventTarget.mixin(BaseTexture.prototype); -Object.defineProperties(BaseTexture.prototype, { - needsUpdate: { - get: function () - { - return this._needsUpdate; - }, - set: function (val) - { - this._needsUpdate = val; - - if (val) - { - this.emit('update', this); - } - } - } -}); +/** + * Updates the texture on all the webgl renderers. + * + * @fires update + */ +BaseTexture.prototype.update = function () { + this.emit('update', this); +}; /** * Load a source. @@ -294,7 +277,7 @@ this.width = this.source.naturalWidth || this.source.width; this.height = this.source.naturalHeight || this.source.height; - this.needsUpdate = true; + this.update(); }; /** diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 0d132c6..8d7b26b 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -65,7 +65,6 @@ var baseTexture = new BaseTexture(); baseTexture.width = width * resolution; baseTexture.height = height * resolution; - baseTexture._glTextures = []; baseTexture.resolution = resolution; baseTexture.scaleMode = scaleMode || CONST.scaleModes.DEFAULT; baseTexture.hasLoaded = true; diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 949991d..3198a53 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -105,6 +105,20 @@ */ this.crop = crop || frame;//new math.Rectangle(0, 0, 1, 1); + /** + * The pivot point to used for a sprite this texture belongs to. + * + * @member {Point} + */ + this.spritePivot = new math.Point(); + + /** + * The rotation value of the texture, copied to a sprite when assigned to it. + * + * @member {number} + */ + this.rotation = 0; + if (baseTexture.hasLoaded) { if (this.noFrame) @@ -125,17 +139,6 @@ eventTarget.mixin(Texture.prototype); Object.defineProperties(Texture.prototype, { - needsUpdate: { - get: function () - { - return this.baseTexture.needsUpdate; - }, - set: function (val) - { - this.baseTexture.needsUpdate = val; - } - }, - frame: { get: function () { @@ -176,6 +179,15 @@ }); /** + * Updates this texture on the gpu. + * + */ +Texture.prototype.update = function () +{ + this.baseTexture.update(); +}; + +/** * Called when the base texture is loaded * * @private diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index f03ef64..fb658ec 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -56,7 +56,7 @@ if (this.autoUpdate) { window.requestAnimationFrame(this._boundOnUpdate); - this.needsUpdate = true; + this.update(); } }; diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 25b5a0e..4c90363 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -13,7 +13,7 @@ */ function TilingSprite(texture, width, height) { - core.Sprite.call( this, texture); + core.Sprite.call(this, texture); /** * The with of the tiling sprite @@ -129,15 +129,6 @@ if (!this.tilingTexture || this._refreshTexture) { this.generateTilingTexture(true); - - if (this.tilingTexture && this.tilingTexture.needsUpdate) - { - //TODO - tweaking - renderer.updateTexture(this.tilingTexture.baseTexture); - this.tilingTexture.needsUpdate = false; - // this.tilingTexture._uvs = null; - } - } else { @@ -413,7 +404,7 @@ canvasBuffer.resize(targetWidth, targetHeight); this.tilingTexture.baseTexture.width = targetWidth; this.tilingTexture.baseTexture.height = targetHeight; - this.tilingTexture.needsUpdate = true; + this.tilingTexture.update(); } else { diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 7b7421a..a07e0d5 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -20,8 +20,6 @@ { Container.call(this); - this.renderable = true; - /** * The alpha value used when filling the Graphics object. * diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 1c131bb..39a9754 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -363,7 +363,7 @@ // empty all the old gl textures as they are useless now for (var key in utils.BaseTextureCache) { - utils.BaseTextureCache[key]._glTextures = {}; + utils.BaseTextureCache[key]._glTextures.length = 0; } }; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index f246832..0105965 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -80,8 +80,6 @@ */ this.shader = null; - this.renderable = true; - this.cachedTint = 0xFFFFFF; // call texture setter @@ -199,6 +197,12 @@ { this.scale.y = this._height / this.texture.frame.height; } + + if (this.texture.rotation) { + this.rotation = this.texture.rotation; + // this.pivot.x = this.texture.spritePivot.x; + // this.pivot.y = this.texture.spritePivot.y; + } }; Sprite.prototype._renderWebGL = function (renderer) diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 684eee3..fe0533c 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -113,15 +113,7 @@ * @member {object} * @private */ - this._glTextures = {}; - - /** - * Does the texture on the GPU need to be updated? - * - * @member {boolean} - * @private - */ - this._needsUpdate = false; + this._glTextures = []; // if no source passed don't try to load if (source) @@ -149,23 +141,14 @@ utils.eventTarget.mixin(BaseTexture.prototype); -Object.defineProperties(BaseTexture.prototype, { - needsUpdate: { - get: function () - { - return this._needsUpdate; - }, - set: function (val) - { - this._needsUpdate = val; - - if (val) - { - this.emit('update', this); - } - } - } -}); +/** + * Updates the texture on all the webgl renderers. + * + * @fires update + */ +BaseTexture.prototype.update = function () { + this.emit('update', this); +}; /** * Load a source. @@ -294,7 +277,7 @@ this.width = this.source.naturalWidth || this.source.width; this.height = this.source.naturalHeight || this.source.height; - this.needsUpdate = true; + this.update(); }; /** diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 0d132c6..8d7b26b 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -65,7 +65,6 @@ var baseTexture = new BaseTexture(); baseTexture.width = width * resolution; baseTexture.height = height * resolution; - baseTexture._glTextures = []; baseTexture.resolution = resolution; baseTexture.scaleMode = scaleMode || CONST.scaleModes.DEFAULT; baseTexture.hasLoaded = true; diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 949991d..3198a53 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -105,6 +105,20 @@ */ this.crop = crop || frame;//new math.Rectangle(0, 0, 1, 1); + /** + * The pivot point to used for a sprite this texture belongs to. + * + * @member {Point} + */ + this.spritePivot = new math.Point(); + + /** + * The rotation value of the texture, copied to a sprite when assigned to it. + * + * @member {number} + */ + this.rotation = 0; + if (baseTexture.hasLoaded) { if (this.noFrame) @@ -125,17 +139,6 @@ eventTarget.mixin(Texture.prototype); Object.defineProperties(Texture.prototype, { - needsUpdate: { - get: function () - { - return this.baseTexture.needsUpdate; - }, - set: function (val) - { - this.baseTexture.needsUpdate = val; - } - }, - frame: { get: function () { @@ -176,6 +179,15 @@ }); /** + * Updates this texture on the gpu. + * + */ +Texture.prototype.update = function () +{ + this.baseTexture.update(); +}; + +/** * Called when the base texture is loaded * * @private diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index f03ef64..fb658ec 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -56,7 +56,7 @@ if (this.autoUpdate) { window.requestAnimationFrame(this._boundOnUpdate); - this.needsUpdate = true; + this.update(); } }; diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 25b5a0e..4c90363 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -13,7 +13,7 @@ */ function TilingSprite(texture, width, height) { - core.Sprite.call( this, texture); + core.Sprite.call(this, texture); /** * The with of the tiling sprite @@ -129,15 +129,6 @@ if (!this.tilingTexture || this._refreshTexture) { this.generateTilingTexture(true); - - if (this.tilingTexture && this.tilingTexture.needsUpdate) - { - //TODO - tweaking - renderer.updateTexture(this.tilingTexture.baseTexture); - this.tilingTexture.needsUpdate = false; - // this.tilingTexture._uvs = null; - } - } else { @@ -413,7 +404,7 @@ canvasBuffer.resize(targetWidth, targetHeight); this.tilingTexture.baseTexture.width = targetWidth; this.tilingTexture.baseTexture.height = targetHeight; - this.tilingTexture.needsUpdate = true; + this.tilingTexture.update(); } else { diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index d12425e..e3e522f 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -20,8 +20,10 @@ } } + var name = resource.data.nodeName; + // skip if no data - if (!resource.data) + if (!resource.data || !name || name.toLowerCase() !== '#document' || name.toLowerCase() !== 'div') { return next(); } diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 7b7421a..a07e0d5 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -20,8 +20,6 @@ { Container.call(this); - this.renderable = true; - /** * The alpha value used when filling the Graphics object. * diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 1c131bb..39a9754 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -363,7 +363,7 @@ // empty all the old gl textures as they are useless now for (var key in utils.BaseTextureCache) { - utils.BaseTextureCache[key]._glTextures = {}; + utils.BaseTextureCache[key]._glTextures.length = 0; } }; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index f246832..0105965 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -80,8 +80,6 @@ */ this.shader = null; - this.renderable = true; - this.cachedTint = 0xFFFFFF; // call texture setter @@ -199,6 +197,12 @@ { this.scale.y = this._height / this.texture.frame.height; } + + if (this.texture.rotation) { + this.rotation = this.texture.rotation; + // this.pivot.x = this.texture.spritePivot.x; + // this.pivot.y = this.texture.spritePivot.y; + } }; Sprite.prototype._renderWebGL = function (renderer) diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 684eee3..fe0533c 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -113,15 +113,7 @@ * @member {object} * @private */ - this._glTextures = {}; - - /** - * Does the texture on the GPU need to be updated? - * - * @member {boolean} - * @private - */ - this._needsUpdate = false; + this._glTextures = []; // if no source passed don't try to load if (source) @@ -149,23 +141,14 @@ utils.eventTarget.mixin(BaseTexture.prototype); -Object.defineProperties(BaseTexture.prototype, { - needsUpdate: { - get: function () - { - return this._needsUpdate; - }, - set: function (val) - { - this._needsUpdate = val; - - if (val) - { - this.emit('update', this); - } - } - } -}); +/** + * Updates the texture on all the webgl renderers. + * + * @fires update + */ +BaseTexture.prototype.update = function () { + this.emit('update', this); +}; /** * Load a source. @@ -294,7 +277,7 @@ this.width = this.source.naturalWidth || this.source.width; this.height = this.source.naturalHeight || this.source.height; - this.needsUpdate = true; + this.update(); }; /** diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 0d132c6..8d7b26b 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -65,7 +65,6 @@ var baseTexture = new BaseTexture(); baseTexture.width = width * resolution; baseTexture.height = height * resolution; - baseTexture._glTextures = []; baseTexture.resolution = resolution; baseTexture.scaleMode = scaleMode || CONST.scaleModes.DEFAULT; baseTexture.hasLoaded = true; diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 949991d..3198a53 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -105,6 +105,20 @@ */ this.crop = crop || frame;//new math.Rectangle(0, 0, 1, 1); + /** + * The pivot point to used for a sprite this texture belongs to. + * + * @member {Point} + */ + this.spritePivot = new math.Point(); + + /** + * The rotation value of the texture, copied to a sprite when assigned to it. + * + * @member {number} + */ + this.rotation = 0; + if (baseTexture.hasLoaded) { if (this.noFrame) @@ -125,17 +139,6 @@ eventTarget.mixin(Texture.prototype); Object.defineProperties(Texture.prototype, { - needsUpdate: { - get: function () - { - return this.baseTexture.needsUpdate; - }, - set: function (val) - { - this.baseTexture.needsUpdate = val; - } - }, - frame: { get: function () { @@ -176,6 +179,15 @@ }); /** + * Updates this texture on the gpu. + * + */ +Texture.prototype.update = function () +{ + this.baseTexture.update(); +}; + +/** * Called when the base texture is loaded * * @private diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index f03ef64..fb658ec 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -56,7 +56,7 @@ if (this.autoUpdate) { window.requestAnimationFrame(this._boundOnUpdate); - this.needsUpdate = true; + this.update(); } }; diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 25b5a0e..4c90363 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -13,7 +13,7 @@ */ function TilingSprite(texture, width, height) { - core.Sprite.call( this, texture); + core.Sprite.call(this, texture); /** * The with of the tiling sprite @@ -129,15 +129,6 @@ if (!this.tilingTexture || this._refreshTexture) { this.generateTilingTexture(true); - - if (this.tilingTexture && this.tilingTexture.needsUpdate) - { - //TODO - tweaking - renderer.updateTexture(this.tilingTexture.baseTexture); - this.tilingTexture.needsUpdate = false; - // this.tilingTexture._uvs = null; - } - } else { @@ -413,7 +404,7 @@ canvasBuffer.resize(targetWidth, targetHeight); this.tilingTexture.baseTexture.width = targetWidth; this.tilingTexture.baseTexture.height = targetHeight; - this.tilingTexture.needsUpdate = true; + this.tilingTexture.update(); } else { diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index d12425e..e3e522f 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -20,8 +20,10 @@ } } + var name = resource.data.nodeName; + // skip if no data - if (!resource.data) + if (!resource.data || !name || name.toLowerCase() !== '#document' || name.toLowerCase() !== 'div') { return next(); } diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index 2d778b7..859633a 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -1,4 +1,5 @@ var Resource = require('resource-loader').Resource, + path = require('path'), core = require('../core'); module.exports = function () @@ -13,8 +14,10 @@ loadType: Resource.LOAD_TYPE.IMAGE }; + var route = path.dirname(resource.url.replace(this.baseUrl, '')); + // load the image for this sheet - this.loadResource(new Resource(this.baseUrl + resource.data.meta.image, loadOptions), function (res) + this.loadResource(new Resource(this.baseUrl + route + '/' + resource.data.meta.image, loadOptions), function (res) { resource.textures = {}; @@ -26,9 +29,16 @@ if (rect) { - var size = new core.math.Rectangle(rect.x, rect.y, rect.w, rect.h); + var size = null; var trim = null; + if (frames[i].rotated) { + size = new core.math.Rectangle(rect.x, rect.y, rect.h, rect.w); + } + else { + size = new core.math.Rectangle(rect.x, rect.y, rect.w, rect.h); + } + // Check to see if the sprite is trimmed if (frames[i].trimmed) { @@ -41,6 +51,12 @@ } resource.textures[i] = new core.Texture(res.texture.baseTexture, size, size.clone(), trim); + + if (frames[i].rotated) { + resource.textures[i].spritePivot.x = frames[i].pivot.x; + resource.textures[i].spritePivot.y = frames[i].pivot.y; + resource.textures[i].rotation = -Math.PI / 2; + } } } diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 7b7421a..a07e0d5 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -20,8 +20,6 @@ { Container.call(this); - this.renderable = true; - /** * The alpha value used when filling the Graphics object. * diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 1c131bb..39a9754 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -363,7 +363,7 @@ // empty all the old gl textures as they are useless now for (var key in utils.BaseTextureCache) { - utils.BaseTextureCache[key]._glTextures = {}; + utils.BaseTextureCache[key]._glTextures.length = 0; } }; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index f246832..0105965 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -80,8 +80,6 @@ */ this.shader = null; - this.renderable = true; - this.cachedTint = 0xFFFFFF; // call texture setter @@ -199,6 +197,12 @@ { this.scale.y = this._height / this.texture.frame.height; } + + if (this.texture.rotation) { + this.rotation = this.texture.rotation; + // this.pivot.x = this.texture.spritePivot.x; + // this.pivot.y = this.texture.spritePivot.y; + } }; Sprite.prototype._renderWebGL = function (renderer) diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 684eee3..fe0533c 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -113,15 +113,7 @@ * @member {object} * @private */ - this._glTextures = {}; - - /** - * Does the texture on the GPU need to be updated? - * - * @member {boolean} - * @private - */ - this._needsUpdate = false; + this._glTextures = []; // if no source passed don't try to load if (source) @@ -149,23 +141,14 @@ utils.eventTarget.mixin(BaseTexture.prototype); -Object.defineProperties(BaseTexture.prototype, { - needsUpdate: { - get: function () - { - return this._needsUpdate; - }, - set: function (val) - { - this._needsUpdate = val; - - if (val) - { - this.emit('update', this); - } - } - } -}); +/** + * Updates the texture on all the webgl renderers. + * + * @fires update + */ +BaseTexture.prototype.update = function () { + this.emit('update', this); +}; /** * Load a source. @@ -294,7 +277,7 @@ this.width = this.source.naturalWidth || this.source.width; this.height = this.source.naturalHeight || this.source.height; - this.needsUpdate = true; + this.update(); }; /** diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 0d132c6..8d7b26b 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -65,7 +65,6 @@ var baseTexture = new BaseTexture(); baseTexture.width = width * resolution; baseTexture.height = height * resolution; - baseTexture._glTextures = []; baseTexture.resolution = resolution; baseTexture.scaleMode = scaleMode || CONST.scaleModes.DEFAULT; baseTexture.hasLoaded = true; diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 949991d..3198a53 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -105,6 +105,20 @@ */ this.crop = crop || frame;//new math.Rectangle(0, 0, 1, 1); + /** + * The pivot point to used for a sprite this texture belongs to. + * + * @member {Point} + */ + this.spritePivot = new math.Point(); + + /** + * The rotation value of the texture, copied to a sprite when assigned to it. + * + * @member {number} + */ + this.rotation = 0; + if (baseTexture.hasLoaded) { if (this.noFrame) @@ -125,17 +139,6 @@ eventTarget.mixin(Texture.prototype); Object.defineProperties(Texture.prototype, { - needsUpdate: { - get: function () - { - return this.baseTexture.needsUpdate; - }, - set: function (val) - { - this.baseTexture.needsUpdate = val; - } - }, - frame: { get: function () { @@ -176,6 +179,15 @@ }); /** + * Updates this texture on the gpu. + * + */ +Texture.prototype.update = function () +{ + this.baseTexture.update(); +}; + +/** * Called when the base texture is loaded * * @private diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index f03ef64..fb658ec 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -56,7 +56,7 @@ if (this.autoUpdate) { window.requestAnimationFrame(this._boundOnUpdate); - this.needsUpdate = true; + this.update(); } }; diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 25b5a0e..4c90363 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -13,7 +13,7 @@ */ function TilingSprite(texture, width, height) { - core.Sprite.call( this, texture); + core.Sprite.call(this, texture); /** * The with of the tiling sprite @@ -129,15 +129,6 @@ if (!this.tilingTexture || this._refreshTexture) { this.generateTilingTexture(true); - - if (this.tilingTexture && this.tilingTexture.needsUpdate) - { - //TODO - tweaking - renderer.updateTexture(this.tilingTexture.baseTexture); - this.tilingTexture.needsUpdate = false; - // this.tilingTexture._uvs = null; - } - } else { @@ -413,7 +404,7 @@ canvasBuffer.resize(targetWidth, targetHeight); this.tilingTexture.baseTexture.width = targetWidth; this.tilingTexture.baseTexture.height = targetHeight; - this.tilingTexture.needsUpdate = true; + this.tilingTexture.update(); } else { diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index d12425e..e3e522f 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -20,8 +20,10 @@ } } + var name = resource.data.nodeName; + // skip if no data - if (!resource.data) + if (!resource.data || !name || name.toLowerCase() !== '#document' || name.toLowerCase() !== 'div') { return next(); } diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index 2d778b7..859633a 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -1,4 +1,5 @@ var Resource = require('resource-loader').Resource, + path = require('path'), core = require('../core'); module.exports = function () @@ -13,8 +14,10 @@ loadType: Resource.LOAD_TYPE.IMAGE }; + var route = path.dirname(resource.url.replace(this.baseUrl, '')); + // load the image for this sheet - this.loadResource(new Resource(this.baseUrl + resource.data.meta.image, loadOptions), function (res) + this.loadResource(new Resource(this.baseUrl + route + '/' + resource.data.meta.image, loadOptions), function (res) { resource.textures = {}; @@ -26,9 +29,16 @@ if (rect) { - var size = new core.math.Rectangle(rect.x, rect.y, rect.w, rect.h); + var size = null; var trim = null; + if (frames[i].rotated) { + size = new core.math.Rectangle(rect.x, rect.y, rect.h, rect.w); + } + else { + size = new core.math.Rectangle(rect.x, rect.y, rect.w, rect.h); + } + // Check to see if the sprite is trimmed if (frames[i].trimmed) { @@ -41,6 +51,12 @@ } resource.textures[i] = new core.Texture(res.texture.baseTexture, size, size.clone(), trim); + + if (frames[i].rotated) { + resource.textures[i].spritePivot.x = frames[i].pivot.x; + resource.textures[i].spritePivot.y = frames[i].pivot.y; + resource.textures[i].rotation = -Math.PI / 2; + } } } diff --git a/src/text/Text.js b/src/text/Text.js index 9974861..a6b337a 100644 --- a/src/text/Text.js +++ b/src/text/Text.js @@ -69,6 +69,10 @@ Text.prototype.constructor = Text; module.exports = Text; +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set @@ -117,22 +121,22 @@ }, /** - * Set the style of the text - * - * @param [style] {object} The style parameters - * @param [style.font='bold 20pt Arial'] {string} The style and size of the font - * @param [style.fill='black'] {object} A canvas fillstyle that will be used on the text eg 'red', '#00FF00' - * @param [style.align='left'] {string} Alignment for multiline text ('left', 'center' or 'right'), does not affect single line text - * @param [style.stroke='black'] {string} A canvas fillstyle that will be used on the text stroke eg 'blue', '#FCFF00' - * @param [style.strokeThickness=0] {number} A number that represents the thickness of the stroke. Default is 0 (no stroke) - * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used - * @param [style.wordWrapWidth=100] {number} The width at which text will wrap - * @param [style.dropShadow=false] {boolean} Set a drop shadow for the text - * @param [style.dropShadowColor='#000000'] {string} A fill style to be used on the dropshadow e.g 'red', '#00FF00' - * @param [style.dropShadowAngle=Math.PI/4] {number} Set a angle of the drop shadow - * @param [style.dropShadowDistance=5] {number} Set a distance of the drop shadow - * @memberof Text# - */ + * Set the style of the text + * + * @param [style] {object} The style parameters + * @param [style.font='bold 20pt Arial'] {string} The style and size of the font + * @param [style.fill='black'] {object} A canvas fillstyle that will be used on the text eg 'red', '#00FF00' + * @param [style.align='left'] {string} Alignment for multiline text ('left', 'center' or 'right'), does not affect single line text + * @param [style.stroke='black'] {string} A canvas fillstyle that will be used on the text stroke eg 'blue', '#FCFF00' + * @param [style.strokeThickness=0] {number} A number that represents the thickness of the stroke. Default is 0 (no stroke) + * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used + * @param [style.wordWrapWidth=100] {number} The width at which text will wrap + * @param [style.dropShadow=false] {boolean} Set a drop shadow for the text + * @param [style.dropShadowColor='#000000'] {string} A fill style to be used on the dropshadow e.g 'red', '#00FF00' + * @param [style.dropShadowAngle=Math.PI/6] {number} Set a angle of the drop shadow + * @param [style.dropShadowDistance=5] {number} Set a distance of the drop shadow + * @memberof Text# + */ style: { get: function () { @@ -150,9 +154,9 @@ style.wordWrapWidth = style.wordWrapWidth || 100; style.dropShadow = style.dropShadow || false; + style.dropShadowColor = style.dropShadowColor || '#000000'; style.dropShadowAngle = style.dropShadowAngle || Math.PI / 6; - style.dropShadowDistance = style.dropShadowDistance || 4; - style.dropShadowColor = style.dropShadowColor || 'black'; + style.dropShadowDistance = style.dropShadowDistance || 5; this._style = style; this.dirty = true; @@ -160,10 +164,10 @@ }, /** - * Set the copy for the text object. To split a line you can use '\n'. - * - * @param text {string} The copy that you would like the text to display - */ + * Set the copy for the text object. To split a line you can use '\n'. + * + * @param text {string} The copy that you would like the text to display + */ text: { get: function() { @@ -237,10 +241,6 @@ this.context.clearRect(0, 0, this.canvas.width, this.canvas.height); } - // used for debugging.. - //this.context.fillStyle ="#FF0000" - //this.context.fillRect(0, 0, this.canvas.width,this.canvas.height); - this.context.font = style.font; this.context.strokeStyle = style.stroke; this.context.lineWidth = style.strokeThickness; @@ -275,8 +275,6 @@ { this.context.fillText(lines[i], linePositionX + xShadowOffset, linePositionY + yShadowOffset); } - - // if (dropShadow) } } @@ -307,8 +305,6 @@ { this.context.fillText(lines[i], linePositionX, linePositionY); } - - // if (dropShadow) } this.updateTexture(); @@ -329,12 +325,14 @@ this._width = this.canvas.width; this._height = this.canvas.height; + this.texture.update(); + this.dirty = false; }; /** * Renders the object using the WebGL renderer -* + * * @param renderer {WebGLRenderer} */ Text.prototype.renderWebGL = function (renderer) @@ -351,7 +349,7 @@ /** * Renders the object using the Canvas renderer -* + * * @param renderer {CanvasRenderer} */ Text.prototype.renderCanvas = function (renderer) @@ -368,7 +366,7 @@ /** * Calculates the ascent, descent and fontSize of a given fontStyle -* + * * @param fontStyle {object} * @private */ @@ -547,7 +545,3 @@ this.texture.destroy(destroyBaseTexture === undefined ? true : destroyBaseTexture); }; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d');