diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 84c0841..15d26b9 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -275,7 +275,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/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 84c0841..15d26b9 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -275,7 +275,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/test/core/TilingSprite.js b/test/core/TilingSprite.js index 0b6c87f..772ff83 100644 --- a/test/core/TilingSprite.js +++ b/test/core/TilingSprite.js @@ -25,6 +25,87 @@ }); }); + describe('.getLocalBounds()', function () + { + before(function () + { + this.tileSprite = new PIXI.extras.TilingSprite(PIXI.Texture.EMPTY, 1, 2); + this.tileSprite.anchor.set(3, 4); + }); + + beforeEach(function () + { + sinon.stub(PIXI.Sprite.prototype, 'getLocalBounds'); + this.tileSprite._bounds = { getRectangle: sinon.spy() }; + }); + + afterEach(function () + { + PIXI.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(PIXI.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(PIXI.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(PIXI.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(PIXI.Rectangle); + expect(PIXI.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 PIXI.Texture(new PIXI.BaseTexture());