diff --git a/packages/mixin-cache-as-bitmap/src/index.js b/packages/mixin-cache-as-bitmap/src/index.js index 4d03d37..0c65fe8 100644 --- a/packages/mixin-cache-as-bitmap/src/index.js +++ b/packages/mixin-cache-as-bitmap/src/index.js @@ -79,7 +79,7 @@ data.originalRenderCanvas = this.renderCanvas; data.originalUpdateTransform = this.updateTransform; - data.originalCalculateBounds = this._calculateBounds; + data.originalCalculateBounds = this.calculateBounds; data.originalGetLocalBounds = this.getLocalBounds; data.originalDestroy = this.destroy; @@ -105,7 +105,7 @@ this.render = data.originalRender; this.renderCanvas = data.originalRenderCanvas; - this._calculateBounds = data.originalCalculateBounds; + this.calculateBounds = data.originalCalculateBounds; this.getLocalBounds = data.originalGetLocalBounds; this.destroy = data.originalDestroy; @@ -218,7 +218,10 @@ // renderer.filterManager.filterStack = stack; this.render = this._renderCached; + // the rest is the same as for Canvas this.updateTransform = this.displayObjectUpdateTransform; + this.calculateBounds = this._calculateCachedBounds; + this.getLocalBounds = this._getCachedLocalBounds; this._mask = null; this.filterArea = null; @@ -232,10 +235,6 @@ cachedSprite.alpha = cacheAlpha; cachedSprite._bounds = this._bounds; - // easy bounds.. - this._calculateBounds = this._calculateCachedBounds; - this.getLocalBounds = this._getCachedLocalBounds; - this._cacheData.sprite = cachedSprite; this.transform._parentID = -1; @@ -332,7 +331,10 @@ renderer.context = cachedRenderTarget; this.renderCanvas = this._renderCachedCanvas; + // the rest is the same as for WebGL + this.updateTransform = this.displayObjectUpdateTransform; this.calculateBounds = this._calculateCachedBounds; + this.getLocalBounds = this._getCachedLocalBounds; this._mask = null; this.filterArea = null; @@ -343,9 +345,13 @@ 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; + cachedSprite._bounds = this._bounds; + this._cacheData.sprite = cachedSprite; + + this.transform._parentID = -1; + // restore the transform of the cached sprite to avoid the nasty flicker.. if (!this.parent) { this.parent = renderer._tempDisplayObjectParent; @@ -357,10 +363,7 @@ this.updateTransform(); } - this.updateTransform = this.displayObjectUpdateTransform; - - this._cacheData.sprite = cachedSprite; - + // map the hit test.. this.containsPoint = cachedSprite.containsPoint.bind(cachedSprite); };