diff --git a/package.json b/package.json index 51217d5..e4bc1c6 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ }, "dependencies": { "async": "^0.9.0", - "resource-loader": "^1.0.0", + "resource-loader": "^1.1.1", "webgl-enabled": "^1.0.2" }, "browserify": { diff --git a/package.json b/package.json index 51217d5..e4bc1c6 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ }, "dependencies": { "async": "^0.9.0", - "resource-loader": "^1.0.0", + "resource-loader": "^1.1.1", "webgl-enabled": "^1.0.2" }, "browserify": { diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 0105965..669bdb5 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -197,12 +197,6 @@ { 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/package.json b/package.json index 51217d5..e4bc1c6 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ }, "dependencies": { "async": "^0.9.0", - "resource-loader": "^1.0.0", + "resource-loader": "^1.1.1", "webgl-enabled": "^1.0.2" }, "browserify": { diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 0105965..669bdb5 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -197,12 +197,6 @@ { 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/Texture.js b/src/core/textures/Texture.js index 3198a53..2508070 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -106,18 +106,12 @@ this.crop = crop || frame;//new math.Rectangle(0, 0, 1, 1); /** - * The pivot point to used for a sprite this texture belongs to. + * The rotation value of the texture. * - * @member {Point} - */ - this.spritePivot = new math.Point(); - - /** - * The rotation value of the texture, copied to a sprite when assigned to it. - * + * @private * @member {number} */ - this.rotation = 0; + this._rotation = 0; if (baseTexture.hasLoaded) { @@ -175,6 +169,17 @@ this._updateUvs(); } } + }, + rotation: { + get: function () + { + return this._rotation; + }, + set: function (val) { + this._rotation = val; + + this._updateUvs(); + } } }); @@ -253,6 +258,8 @@ this._uvs.x3 = frame.x / tw; this._uvs.y3 = (frame.y + frame.height) / th; + + this._uvs.rotate(this.rotation); }; /** diff --git a/package.json b/package.json index 51217d5..e4bc1c6 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ }, "dependencies": { "async": "^0.9.0", - "resource-loader": "^1.0.0", + "resource-loader": "^1.1.1", "webgl-enabled": "^1.0.2" }, "browserify": { diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 0105965..669bdb5 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -197,12 +197,6 @@ { 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/Texture.js b/src/core/textures/Texture.js index 3198a53..2508070 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -106,18 +106,12 @@ this.crop = crop || frame;//new math.Rectangle(0, 0, 1, 1); /** - * The pivot point to used for a sprite this texture belongs to. + * The rotation value of the texture. * - * @member {Point} - */ - this.spritePivot = new math.Point(); - - /** - * The rotation value of the texture, copied to a sprite when assigned to it. - * + * @private * @member {number} */ - this.rotation = 0; + this._rotation = 0; if (baseTexture.hasLoaded) { @@ -175,6 +169,17 @@ this._updateUvs(); } } + }, + rotation: { + get: function () + { + return this._rotation; + }, + set: function (val) { + this._rotation = val; + + this._updateUvs(); + } } }); @@ -253,6 +258,8 @@ this._uvs.x3 = frame.x / tw; this._uvs.y3 = (frame.y + frame.height) / th; + + this._uvs.rotate(this.rotation); }; /** diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 5424d52..f06eddb 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,3 +1,6 @@ +var halfPI = Math.PI / 2, + x, y; + function TextureUvs() { this.x0 = 0; @@ -14,3 +17,63 @@ } module.exports = TextureUvs; + +TextureUvs.prototype.rotate = function (angle) +{ + if (!angle) + { + return; + } + + // if not a multiple of (PI/2) + if (angle % halfPI) + { + // TODO: Not a multiple of (PI/2)... + } + // shift values for multiples of (PI/2) + else + { + // rotate the uvs by (PI/2) however many times are needed + if (angle > 0) + { + for (var i = angle / halfPI; i > 0; --i) + { + x = this.x3; + y = this.y3; + + this.x3 = this.x2; + this.y3 = this.y2; + + this.x2 = this.x1; + this.y2 = this.y1; + + this.x1 = this.x0; + this.y1 = this.y0; + + this.x0 = x; + this.y0 = y; + } + } + // rotate the uvs by -(PI/2) however many times are needed + else + { + for (var i = angle / halfPI; i < 0; ++i) + { + x = this.x0; + y = this.y0; + + this.x0 = this.x1; + this.y0 = this.y1; + + this.x1 = this.x2; + this.y1 = this.y2; + + this.x2 = this.x3; + this.y2 = this.y3; + + this.x3 = x; + this.y3 = y; + } + } + } +}; diff --git a/package.json b/package.json index 51217d5..e4bc1c6 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ }, "dependencies": { "async": "^0.9.0", - "resource-loader": "^1.0.0", + "resource-loader": "^1.1.1", "webgl-enabled": "^1.0.2" }, "browserify": { diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 0105965..669bdb5 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -197,12 +197,6 @@ { 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/Texture.js b/src/core/textures/Texture.js index 3198a53..2508070 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -106,18 +106,12 @@ this.crop = crop || frame;//new math.Rectangle(0, 0, 1, 1); /** - * The pivot point to used for a sprite this texture belongs to. + * The rotation value of the texture. * - * @member {Point} - */ - this.spritePivot = new math.Point(); - - /** - * The rotation value of the texture, copied to a sprite when assigned to it. - * + * @private * @member {number} */ - this.rotation = 0; + this._rotation = 0; if (baseTexture.hasLoaded) { @@ -175,6 +169,17 @@ this._updateUvs(); } } + }, + rotation: { + get: function () + { + return this._rotation; + }, + set: function (val) { + this._rotation = val; + + this._updateUvs(); + } } }); @@ -253,6 +258,8 @@ this._uvs.x3 = frame.x / tw; this._uvs.y3 = (frame.y + frame.height) / th; + + this._uvs.rotate(this.rotation); }; /** diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 5424d52..f06eddb 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,3 +1,6 @@ +var halfPI = Math.PI / 2, + x, y; + function TextureUvs() { this.x0 = 0; @@ -14,3 +17,63 @@ } module.exports = TextureUvs; + +TextureUvs.prototype.rotate = function (angle) +{ + if (!angle) + { + return; + } + + // if not a multiple of (PI/2) + if (angle % halfPI) + { + // TODO: Not a multiple of (PI/2)... + } + // shift values for multiples of (PI/2) + else + { + // rotate the uvs by (PI/2) however many times are needed + if (angle > 0) + { + for (var i = angle / halfPI; i > 0; --i) + { + x = this.x3; + y = this.y3; + + this.x3 = this.x2; + this.y3 = this.y2; + + this.x2 = this.x1; + this.y2 = this.y1; + + this.x1 = this.x0; + this.y1 = this.y0; + + this.x0 = x; + this.y0 = y; + } + } + // rotate the uvs by -(PI/2) however many times are needed + else + { + for (var i = angle / halfPI; i < 0; ++i) + { + x = this.x0; + y = this.y0; + + this.x0 = this.x1; + this.y0 = this.y1; + + this.x1 = this.x2; + this.y1 = this.y2; + + this.x2 = this.x3; + this.y2 = this.y3; + + this.x3 = x; + this.y3 = y; + } + } + } +}; diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index e3e522f..8c1fa35 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -35,7 +35,7 @@ }; // load the texture for the font - this.loadResource(new Resource(textureUrl, loadOptions), function (res) + this.loadResource(new Resource(resource.name + '_image', textureUrl, loadOptions), function (res) { var data = {}; var info = resource.data.getElementsByTagName('info')[0]; diff --git a/package.json b/package.json index 51217d5..e4bc1c6 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ }, "dependencies": { "async": "^0.9.0", - "resource-loader": "^1.0.0", + "resource-loader": "^1.1.1", "webgl-enabled": "^1.0.2" }, "browserify": { diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 0105965..669bdb5 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -197,12 +197,6 @@ { 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/Texture.js b/src/core/textures/Texture.js index 3198a53..2508070 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -106,18 +106,12 @@ this.crop = crop || frame;//new math.Rectangle(0, 0, 1, 1); /** - * The pivot point to used for a sprite this texture belongs to. + * The rotation value of the texture. * - * @member {Point} - */ - this.spritePivot = new math.Point(); - - /** - * The rotation value of the texture, copied to a sprite when assigned to it. - * + * @private * @member {number} */ - this.rotation = 0; + this._rotation = 0; if (baseTexture.hasLoaded) { @@ -175,6 +169,17 @@ this._updateUvs(); } } + }, + rotation: { + get: function () + { + return this._rotation; + }, + set: function (val) { + this._rotation = val; + + this._updateUvs(); + } } }); @@ -253,6 +258,8 @@ this._uvs.x3 = frame.x / tw; this._uvs.y3 = (frame.y + frame.height) / th; + + this._uvs.rotate(this.rotation); }; /** diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 5424d52..f06eddb 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,3 +1,6 @@ +var halfPI = Math.PI / 2, + x, y; + function TextureUvs() { this.x0 = 0; @@ -14,3 +17,63 @@ } module.exports = TextureUvs; + +TextureUvs.prototype.rotate = function (angle) +{ + if (!angle) + { + return; + } + + // if not a multiple of (PI/2) + if (angle % halfPI) + { + // TODO: Not a multiple of (PI/2)... + } + // shift values for multiples of (PI/2) + else + { + // rotate the uvs by (PI/2) however many times are needed + if (angle > 0) + { + for (var i = angle / halfPI; i > 0; --i) + { + x = this.x3; + y = this.y3; + + this.x3 = this.x2; + this.y3 = this.y2; + + this.x2 = this.x1; + this.y2 = this.y1; + + this.x1 = this.x0; + this.y1 = this.y0; + + this.x0 = x; + this.y0 = y; + } + } + // rotate the uvs by -(PI/2) however many times are needed + else + { + for (var i = angle / halfPI; i < 0; ++i) + { + x = this.x0; + y = this.y0; + + this.x0 = this.x1; + this.y0 = this.y1; + + this.x1 = this.x2; + this.y1 = this.y2; + + this.x2 = this.x3; + this.y2 = this.y3; + + this.x3 = x; + this.y3 = y; + } + } + } +}; diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index e3e522f..8c1fa35 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -35,7 +35,7 @@ }; // load the texture for the font - this.loadResource(new Resource(textureUrl, loadOptions), function (res) + this.loadResource(new Resource(resource.name + '_image', textureUrl, loadOptions), function (res) { var data = {}; var info = resource.data.getElementsByTagName('info')[0]; diff --git a/src/loaders/spineAtlasParser.js b/src/loaders/spineAtlasParser.js index 3083c4a..b7694cc 100644 --- a/src/loaders/spineAtlasParser.js +++ b/src/loaders/spineAtlasParser.js @@ -20,7 +20,7 @@ xhrType: Resource.XHR_RESPONSE_TYPE.TEXT }; - this.loadResource(new Resource(atlasPath, atlasOptions), function (res) + this.loadResource(new Resource(resource.name + '_atlas', atlasPath, atlasOptions), function (res) { // create a spine atlas using the loaded text var spineAtlas = new spine.Atlas(this.ajaxRequest.responseText, this.baseUrl, res.crossOrigin); diff --git a/package.json b/package.json index 51217d5..e4bc1c6 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ }, "dependencies": { "async": "^0.9.0", - "resource-loader": "^1.0.0", + "resource-loader": "^1.1.1", "webgl-enabled": "^1.0.2" }, "browserify": { diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 0105965..669bdb5 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -197,12 +197,6 @@ { 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/Texture.js b/src/core/textures/Texture.js index 3198a53..2508070 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -106,18 +106,12 @@ this.crop = crop || frame;//new math.Rectangle(0, 0, 1, 1); /** - * The pivot point to used for a sprite this texture belongs to. + * The rotation value of the texture. * - * @member {Point} - */ - this.spritePivot = new math.Point(); - - /** - * The rotation value of the texture, copied to a sprite when assigned to it. - * + * @private * @member {number} */ - this.rotation = 0; + this._rotation = 0; if (baseTexture.hasLoaded) { @@ -175,6 +169,17 @@ this._updateUvs(); } } + }, + rotation: { + get: function () + { + return this._rotation; + }, + set: function (val) { + this._rotation = val; + + this._updateUvs(); + } } }); @@ -253,6 +258,8 @@ this._uvs.x3 = frame.x / tw; this._uvs.y3 = (frame.y + frame.height) / th; + + this._uvs.rotate(this.rotation); }; /** diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 5424d52..f06eddb 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,3 +1,6 @@ +var halfPI = Math.PI / 2, + x, y; + function TextureUvs() { this.x0 = 0; @@ -14,3 +17,63 @@ } module.exports = TextureUvs; + +TextureUvs.prototype.rotate = function (angle) +{ + if (!angle) + { + return; + } + + // if not a multiple of (PI/2) + if (angle % halfPI) + { + // TODO: Not a multiple of (PI/2)... + } + // shift values for multiples of (PI/2) + else + { + // rotate the uvs by (PI/2) however many times are needed + if (angle > 0) + { + for (var i = angle / halfPI; i > 0; --i) + { + x = this.x3; + y = this.y3; + + this.x3 = this.x2; + this.y3 = this.y2; + + this.x2 = this.x1; + this.y2 = this.y1; + + this.x1 = this.x0; + this.y1 = this.y0; + + this.x0 = x; + this.y0 = y; + } + } + // rotate the uvs by -(PI/2) however many times are needed + else + { + for (var i = angle / halfPI; i < 0; ++i) + { + x = this.x0; + y = this.y0; + + this.x0 = this.x1; + this.y0 = this.y1; + + this.x1 = this.x2; + this.y1 = this.y2; + + this.x2 = this.x3; + this.y2 = this.y3; + + this.x3 = x; + this.y3 = y; + } + } + } +}; diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index e3e522f..8c1fa35 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -35,7 +35,7 @@ }; // load the texture for the font - this.loadResource(new Resource(textureUrl, loadOptions), function (res) + this.loadResource(new Resource(resource.name + '_image', textureUrl, loadOptions), function (res) { var data = {}; var info = resource.data.getElementsByTagName('info')[0]; diff --git a/src/loaders/spineAtlasParser.js b/src/loaders/spineAtlasParser.js index 3083c4a..b7694cc 100644 --- a/src/loaders/spineAtlasParser.js +++ b/src/loaders/spineAtlasParser.js @@ -20,7 +20,7 @@ xhrType: Resource.XHR_RESPONSE_TYPE.TEXT }; - this.loadResource(new Resource(atlasPath, atlasOptions), function (res) + this.loadResource(new Resource(resource.name + '_atlas', atlasPath, atlasOptions), function (res) { // create a spine atlas using the loaded text var spineAtlas = new spine.Atlas(this.ajaxRequest.responseText, this.baseUrl, res.crossOrigin); diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index 859633a..bb1f665 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -17,7 +17,7 @@ var route = path.dirname(resource.url.replace(this.baseUrl, '')); // load the image for this sheet - this.loadResource(new Resource(this.baseUrl + route + '/' + resource.data.meta.image, loadOptions), function (res) + this.loadResource(new Resource(resource.name + '_image', this.baseUrl + route + '/' + resource.data.meta.image, loadOptions), function (res) { resource.textures = {}; @@ -53,8 +53,8 @@ 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].pivot.x = frames[i].pivot.x; + // resource.textures[i].pivot.y = frames[i].pivot.y; resource.textures[i].rotation = -Math.PI / 2; } }