diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 8fafeb6..087cc0c 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -202,9 +202,10 @@ cachedSprite.anchor.x = -( bounds.x / bounds.width ); cachedSprite.anchor.y = -( bounds.y / bounds.height ); cachedSprite.alpha = cacheAlpha; + cachedSprite._bounds = this._bounds; //easy bounds.. - this._calculateBounds = this._getCachedBounds; + this._calculateBounds = this._calculateCachedBounds; this.getLocalBounds = this._getCachedLocalBounds; this._cacheData.sprite = cachedSprite; @@ -254,6 +255,9 @@ //get bounds actually transforms the object for us already! var bounds = this.getLocalBounds(); + var cacheAlpha = this.alpha; + this.alpha = 1; + var cachedRenderTarget = renderer.context; var renderTexture = new core.RenderTexture.create(bounds.width | 0, bounds.height | 0); @@ -287,6 +291,8 @@ cachedSprite.transform.worldTransform = this.transform.worldTransform; cachedSprite.anchor.x = -( bounds.x / bounds.width ); cachedSprite.anchor.y = -( bounds.y / bounds.height ); + cachedSprite._bounds = this._bounds; + cachedSprite.alpha = cacheAlpha; this.updateTransform(); this.updateTransform = this.displayObjectUpdateTransform; @@ -294,6 +300,8 @@ this._cacheData.sprite = cachedSprite; this.containsPoint = cachedSprite.containsPoint.bind(cachedSprite); + + }; /** diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 8fafeb6..087cc0c 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -202,9 +202,10 @@ cachedSprite.anchor.x = -( bounds.x / bounds.width ); cachedSprite.anchor.y = -( bounds.y / bounds.height ); cachedSprite.alpha = cacheAlpha; + cachedSprite._bounds = this._bounds; //easy bounds.. - this._calculateBounds = this._getCachedBounds; + this._calculateBounds = this._calculateCachedBounds; this.getLocalBounds = this._getCachedLocalBounds; this._cacheData.sprite = cachedSprite; @@ -254,6 +255,9 @@ //get bounds actually transforms the object for us already! var bounds = this.getLocalBounds(); + var cacheAlpha = this.alpha; + this.alpha = 1; + var cachedRenderTarget = renderer.context; var renderTexture = new core.RenderTexture.create(bounds.width | 0, bounds.height | 0); @@ -287,6 +291,8 @@ cachedSprite.transform.worldTransform = this.transform.worldTransform; cachedSprite.anchor.x = -( bounds.x / bounds.width ); cachedSprite.anchor.y = -( bounds.y / bounds.height ); + cachedSprite._bounds = this._bounds; + cachedSprite.alpha = cacheAlpha; this.updateTransform(); this.updateTransform = this.displayObjectUpdateTransform; @@ -294,6 +300,8 @@ this._cacheData.sprite = cachedSprite; this.containsPoint = cachedSprite.containsPoint.bind(cachedSprite); + + }; /** diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js index 2284349..b9f6b2c 100644 --- a/test/core/getLocalBounds.js +++ b/test/core/getLocalBounds.js @@ -114,4 +114,29 @@ expect(bounds.width).to.equal(10); expect(bounds.height).to.equal(10); }); + + it('should register correct local-bounds with a cachAsBitmap item inside after a render', function() { + var parent = new PIXI.Container(); + + var graphic = new PIXI.Graphics(); + + graphic.beginFill(0xffffff); + graphic.drawRect(0,0,100,100); + graphic.endFill(); + graphic.cacheAsBitmap=true; + + parent.addChild(graphic); + + + var renderer = new PIXI.CanvasRenderer(100, 100); + renderer.sayHello = function(){}; + renderer.render(parent); + + var bounds = parent.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(100); + expect(bounds.height).to.equal(100); + }); }); \ No newline at end of file