diff --git a/src/core/textures/Spritesheet.js b/src/core/textures/Spritesheet.js index b890c1a..7b696ff 100644 --- a/src/core/textures/Spritesheet.js +++ b/src/core/textures/Spritesheet.js @@ -53,7 +53,8 @@ * @type {number} */ this.resolution = this._updateResolution( - resolutionFilename || this.baseTexture.imageUrl + resolutionFilename + || (this.baseTexture.resource ? this.baseTexture.resource.url : null) ); /** @@ -111,6 +112,8 @@ // For non-1 resolutions, update baseTexture if (resolution !== 1) { + console.log(this.baseTexture.resolution); + this.baseTexture.resolution = resolution; this.baseTexture.updateResolution(); // this.baseTexture.update(); @@ -152,7 +155,6 @@ { let frameIndex = initialFrameIndex; const maxFrames = Spritesheet.BATCH_SIZE; - const sourceScale = this.baseTexture.sourceScale; while (frameIndex - initialFrameIndex < maxFrames && frameIndex < this._frameKeys.length) { @@ -166,26 +168,26 @@ const orig = new Rectangle( 0, 0, - Math.floor(this._frames[i].sourceSize.w * sourceScale) / this.resolution, - Math.floor(this._frames[i].sourceSize.h * sourceScale) / this.resolution + Math.floor(this._frames[i].sourceSize.w) / this.resolution, + Math.floor(this._frames[i].sourceSize.h) / this.resolution ); if (this._frames[i].rotated) { frame = new Rectangle( - Math.floor(rect.x * sourceScale) / this.resolution, - Math.floor(rect.y * sourceScale) / this.resolution, - Math.floor(rect.h * sourceScale) / this.resolution, - Math.floor(rect.w * sourceScale) / this.resolution + Math.floor(rect.x) / this.resolution, + Math.floor(rect.y) / this.resolution, + Math.floor(rect.h) / this.resolution, + Math.floor(rect.w) / this.resolution ); } else { frame = new Rectangle( - Math.floor(rect.x * sourceScale) / this.resolution, - Math.floor(rect.y * sourceScale) / this.resolution, - Math.floor(rect.w * sourceScale) / this.resolution, - Math.floor(rect.h * sourceScale) / this.resolution + Math.floor(rect.x) / this.resolution, + Math.floor(rect.y) / this.resolution, + Math.floor(rect.w) / this.resolution, + Math.floor(rect.h) / this.resolution ); } @@ -193,10 +195,10 @@ if (this._frames[i].trimmed) { trim = new Rectangle( - Math.floor(this._frames[i].spriteSourceSize.x * sourceScale) / this.resolution, - Math.floor(this._frames[i].spriteSourceSize.y * sourceScale) / this.resolution, - Math.floor(rect.w * sourceScale) / this.resolution, - Math.floor(rect.h * sourceScale) / this.resolution + Math.floor(this._frames[i].spriteSourceSize.x) / this.resolution, + Math.floor(this._frames[i].spriteSourceSize.y) / this.resolution, + Math.floor(rect.w) / this.resolution, + Math.floor(rect.h) / this.resolution ); } diff --git a/src/core/textures/Spritesheet.js b/src/core/textures/Spritesheet.js index b890c1a..7b696ff 100644 --- a/src/core/textures/Spritesheet.js +++ b/src/core/textures/Spritesheet.js @@ -53,7 +53,8 @@ * @type {number} */ this.resolution = this._updateResolution( - resolutionFilename || this.baseTexture.imageUrl + resolutionFilename + || (this.baseTexture.resource ? this.baseTexture.resource.url : null) ); /** @@ -111,6 +112,8 @@ // For non-1 resolutions, update baseTexture if (resolution !== 1) { + console.log(this.baseTexture.resolution); + this.baseTexture.resolution = resolution; this.baseTexture.updateResolution(); // this.baseTexture.update(); @@ -152,7 +155,6 @@ { let frameIndex = initialFrameIndex; const maxFrames = Spritesheet.BATCH_SIZE; - const sourceScale = this.baseTexture.sourceScale; while (frameIndex - initialFrameIndex < maxFrames && frameIndex < this._frameKeys.length) { @@ -166,26 +168,26 @@ const orig = new Rectangle( 0, 0, - Math.floor(this._frames[i].sourceSize.w * sourceScale) / this.resolution, - Math.floor(this._frames[i].sourceSize.h * sourceScale) / this.resolution + Math.floor(this._frames[i].sourceSize.w) / this.resolution, + Math.floor(this._frames[i].sourceSize.h) / this.resolution ); if (this._frames[i].rotated) { frame = new Rectangle( - Math.floor(rect.x * sourceScale) / this.resolution, - Math.floor(rect.y * sourceScale) / this.resolution, - Math.floor(rect.h * sourceScale) / this.resolution, - Math.floor(rect.w * sourceScale) / this.resolution + Math.floor(rect.x) / this.resolution, + Math.floor(rect.y) / this.resolution, + Math.floor(rect.h) / this.resolution, + Math.floor(rect.w) / this.resolution ); } else { frame = new Rectangle( - Math.floor(rect.x * sourceScale) / this.resolution, - Math.floor(rect.y * sourceScale) / this.resolution, - Math.floor(rect.w * sourceScale) / this.resolution, - Math.floor(rect.h * sourceScale) / this.resolution + Math.floor(rect.x) / this.resolution, + Math.floor(rect.y) / this.resolution, + Math.floor(rect.w) / this.resolution, + Math.floor(rect.h) / this.resolution ); } @@ -193,10 +195,10 @@ if (this._frames[i].trimmed) { trim = new Rectangle( - Math.floor(this._frames[i].spriteSourceSize.x * sourceScale) / this.resolution, - Math.floor(this._frames[i].spriteSourceSize.y * sourceScale) / this.resolution, - Math.floor(rect.w * sourceScale) / this.resolution, - Math.floor(rect.h * sourceScale) / this.resolution + Math.floor(this._frames[i].spriteSourceSize.x) / this.resolution, + Math.floor(this._frames[i].spriteSourceSize.y) / this.resolution, + Math.floor(rect.w) / this.resolution, + Math.floor(rect.h) / this.resolution ); } diff --git a/test/core/Spritesheet.js b/test/core/Spritesheet.js index dccde04..678ef1d 100644 --- a/test/core/Spritesheet.js +++ b/test/core/Spritesheet.js @@ -12,8 +12,8 @@ spritesheet.parse(function (textures) { const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w * spritesheet.baseTexture.sourceScale); - const height = Math.floor(spritesheet.data.frames[id].frame.h * spritesheet.baseTexture.sourceScale); + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); expect(Object.keys(textures).length).to.equal(1); expect(Object.keys(spritesheet.textures).length).to.equal(1); @@ -42,6 +42,7 @@ frames: {}, meta: {}, }; + const spritesheet = new PIXI.Spritesheet(baseTexture, data); expect(spritesheet.data).to.equal(data); @@ -65,7 +66,6 @@ expect(data).to.be.an.object; expect(data.meta.image).to.equal('building1.png'); expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); }; });