diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index f122a45..6f0a417 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -693,6 +693,7 @@ this.lineWidth = 0; this.filling = false; + this.boundsDirty = -1; this.dirty++; this.clearDirty++; this.graphicsData.length = 0; diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index f122a45..6f0a417 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -693,6 +693,7 @@ this.lineWidth = 0; this.filling = false; + this.boundsDirty = -1; this.dirty++; this.clearDirty++; this.graphicsData.length = 0; diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js index d3d4404..d160a56 100644 --- a/test/core/getLocalBounds.js +++ b/test/core/getLocalBounds.js @@ -50,6 +50,68 @@ expect(bounds.height).to.equal(20); }); + it('should register correct local-bounds with Graphics after clear', function () + { + const parent = new PIXI.Container(); + + const graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawRect(0, 0, 20, 20); + + parent.addChild(graphics); + + let bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.clear(); + graphics.beginFill(0xFF, 1); + graphics.drawRect(0, 0, 10, 10); + graphics.endFill(); + + bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct local-bounds with Graphics after generateCanvasTexture and clear', function () + { + const parent = new PIXI.Container(); + + const graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawRect(0, 0, 20, 20); + + parent.addChild(graphics); + + let bounds = graphics.getLocalBounds(); + + graphics.generateCanvasTexture(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.clear(); + graphics.beginFill(0xFF, 1); + graphics.drawRect(0, 0, 10, 10); + graphics.endFill(); + + bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + it('should register correct local-bounds with an empty Container', function () { const parent = new PIXI.Container();