diff --git a/src/core/textures/Spritesheet.js b/src/core/textures/Spritesheet.js index 85abccf..1a9223f 100644 --- a/src/core/textures/Spritesheet.js +++ b/src/core/textures/Spritesheet.js @@ -151,6 +151,7 @@ { let frameIndex = initialFrameIndex; const maxFrames = Spritesheet.BATCH_SIZE; + const sourceScale = this.baseTexture.sourceScale; while (frameIndex - initialFrameIndex < maxFrames && frameIndex < this._frameKeys.length) { @@ -164,26 +165,26 @@ const orig = new Rectangle( 0, 0, - this._frames[i].sourceSize.w / this.resolution, - this._frames[i].sourceSize.h / this.resolution + Math.floor(this._frames[i].sourceSize.w * sourceScale) / this.resolution, + Math.floor(this._frames[i].sourceSize.h * sourceScale) / this.resolution ); if (this._frames[i].rotated) { frame = new Rectangle( - rect.x / this.resolution, - rect.y / this.resolution, - rect.h / this.resolution, - rect.w / this.resolution + 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 ); } else { frame = new Rectangle( - rect.x / this.resolution, - rect.y / this.resolution, - rect.w / this.resolution, - rect.h / this.resolution + 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 ); } @@ -191,10 +192,10 @@ if (this._frames[i].trimmed) { trim = new Rectangle( - this._frames[i].spriteSourceSize.x / this.resolution, - this._frames[i].spriteSourceSize.y / this.resolution, - rect.w / this.resolution, - rect.h / this.resolution + 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 ); } diff --git a/src/core/textures/Spritesheet.js b/src/core/textures/Spritesheet.js index 85abccf..1a9223f 100644 --- a/src/core/textures/Spritesheet.js +++ b/src/core/textures/Spritesheet.js @@ -151,6 +151,7 @@ { let frameIndex = initialFrameIndex; const maxFrames = Spritesheet.BATCH_SIZE; + const sourceScale = this.baseTexture.sourceScale; while (frameIndex - initialFrameIndex < maxFrames && frameIndex < this._frameKeys.length) { @@ -164,26 +165,26 @@ const orig = new Rectangle( 0, 0, - this._frames[i].sourceSize.w / this.resolution, - this._frames[i].sourceSize.h / this.resolution + Math.floor(this._frames[i].sourceSize.w * sourceScale) / this.resolution, + Math.floor(this._frames[i].sourceSize.h * sourceScale) / this.resolution ); if (this._frames[i].rotated) { frame = new Rectangle( - rect.x / this.resolution, - rect.y / this.resolution, - rect.h / this.resolution, - rect.w / this.resolution + 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 ); } else { frame = new Rectangle( - rect.x / this.resolution, - rect.y / this.resolution, - rect.w / this.resolution, - rect.h / this.resolution + 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 ); } @@ -191,10 +192,10 @@ if (this._frames[i].trimmed) { trim = new Rectangle( - this._frames[i].spriteSourceSize.x / this.resolution, - this._frames[i].spriteSourceSize.y / this.resolution, - rect.w / this.resolution, - rect.h / this.resolution + 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 ); } diff --git a/test/core/Spritesheet.js b/test/core/Spritesheet.js index 7a3d6ac..dccde04 100644 --- a/test/core/Spritesheet.js +++ b/test/core/Spritesheet.js @@ -12,12 +12,14 @@ 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); expect(Object.keys(textures).length).to.equal(1); expect(Object.keys(spritesheet.textures).length).to.equal(1); expect(textures[id]).to.be.an.instanceof(PIXI.Texture); - expect(textures[id].width).to.equal(spritesheet.data.frames[id].frame.w / spritesheet.resolution); - expect(textures[id].height).to.equal(spritesheet.data.frames[id].frame.h / spritesheet.resolution); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); spritesheet.destroy(true); expect(spritesheet.textures).to.be.null; @@ -68,6 +70,19 @@ }; }); + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new PIXI.BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new PIXI.Spritesheet(baseTexture, data); + + 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); + }); + it('should create instance with filename resolution', function (done) { const uri = path.resolve(this.resources, 'building1@2x.json');