diff --git a/packages/sprite-tiling/src/TilingSprite.js b/packages/sprite-tiling/src/TilingSprite.js index b1bd0c4..77a6491 100644 --- a/packages/sprite-tiling/src/TilingSprite.js +++ b/packages/sprite-tiling/src/TilingSprite.js @@ -192,7 +192,7 @@ this._bounds.minX = this._width * -this._anchor._x; this._bounds.minY = this._height * -this._anchor._y; this._bounds.maxX = this._width * (1 - this._anchor._x); - this._bounds.maxY = this._height * (1 - this._anchor._x); + this._bounds.maxY = this._height * (1 - this._anchor._y); if (!rect) { diff --git a/packages/sprite-tiling/src/TilingSprite.js b/packages/sprite-tiling/src/TilingSprite.js index b1bd0c4..77a6491 100644 --- a/packages/sprite-tiling/src/TilingSprite.js +++ b/packages/sprite-tiling/src/TilingSprite.js @@ -192,7 +192,7 @@ this._bounds.minX = this._width * -this._anchor._x; this._bounds.minY = this._height * -this._anchor._y; this._bounds.maxX = this._width * (1 - this._anchor._x); - this._bounds.maxY = this._height * (1 - this._anchor._x); + this._bounds.maxY = this._height * (1 - this._anchor._y); if (!rect) { diff --git a/packages/sprite-tiling/test/index.js b/packages/sprite-tiling/test/index.js index 496ff10..c9ba8f4 100644 --- a/packages/sprite-tiling/test/index.js +++ b/packages/sprite-tiling/test/index.js @@ -1,6 +1,7 @@ const { Container } = require('@pixi/display'); const { Texture, BaseTexture } = require('@pixi/core'); -const { Point } = require('@pixi/math'); +const { Point, Rectangle } = require('@pixi/math'); +const { Sprite } = require('@pixi/sprite'); const { TilingSprite } = require('../'); describe('PIXI.TilingSprite', function () @@ -28,6 +29,87 @@ }); }); + describe('.getLocalBounds()', function () + { + before(function () + { + this.tileSprite = new TilingSprite(Texture.EMPTY, 1, 2); + this.tileSprite.anchor.set(3, 4); + }); + + beforeEach(function () + { + sinon.stub(Sprite.prototype, 'getLocalBounds'); + this.tileSprite._bounds = { getRectangle: sinon.spy() }; + }); + + afterEach(function () + { + Sprite.prototype.getLocalBounds.restore(); + }); + + after(function () + { + this.tileSprite.destroy(); + this.tileSprite = null; + }); + + it('should call parent method if there are children', function () + { + this.tileSprite.children.length = 1; + this.tileSprite.getLocalBounds(); + expect(Sprite.prototype.getLocalBounds).to.be.calledOnce; + expect(this.tileSprite._bounds.getRectangle).to.not.be.called; + }); + + it('should make quick calc if no children', function () + { + this.tileSprite.children.length = 0; + this.tileSprite.getLocalBounds('dummy'); + + expect(this.tileSprite._bounds.getRectangle).to.be.calledOnce; + expect(this.tileSprite._bounds.getRectangle.args[0][0]).to.be.equal('dummy'); + expect(Sprite.prototype.getLocalBounds).to.not.be.called; + + expect(this.tileSprite._bounds.minX).to.be.equal(-3); + expect(this.tileSprite._bounds.minY).to.be.equal(-8); + expect(this.tileSprite._bounds.maxX).to.be.equal(-2); + expect(this.tileSprite._bounds.maxY).to.be.equal(-6); + }); + + it('should assign default rect if rect is not specified', function () + { + this.tileSprite.children.length = 0; + this.tileSprite._localBoundsRect = 'localRect'; + this.tileSprite.getLocalBounds(); + + expect(this.tileSprite._bounds.getRectangle).to.be.calledOnce; + expect(this.tileSprite._bounds.getRectangle.args[0][0]).to.be.equal('localRect'); + expect(Sprite.prototype.getLocalBounds).to.not.be.called; + + expect(this.tileSprite._bounds.minX).to.be.equal(-3); + expect(this.tileSprite._bounds.minY).to.be.equal(-8); + expect(this.tileSprite._bounds.maxX).to.be.equal(-2); + expect(this.tileSprite._bounds.maxY).to.be.equal(-6); + }); + + it('should create and assign rect if default rect is not', function () + { + this.tileSprite.children.length = 0; + this.tileSprite._localBoundsRect = null; + this.tileSprite.getLocalBounds(); + + expect(this.tileSprite._bounds.getRectangle).to.be.calledOnce; + expect(this.tileSprite._bounds.getRectangle.args[0][0]).to.be.instanceof(Rectangle); + expect(Sprite.prototype.getLocalBounds).to.not.be.called; + + expect(this.tileSprite._bounds.minX).to.be.equal(-3); + expect(this.tileSprite._bounds.minY).to.be.equal(-8); + expect(this.tileSprite._bounds.maxX).to.be.equal(-2); + expect(this.tileSprite._bounds.maxY).to.be.equal(-6); + }); + }); + it('checks if tilingSprite contains a point', function () { const texture = new Texture(new BaseTexture());