@@ -39,10 +39,9 @@ class SpriteRendererCanvas extends Renderer {
3939 let desiredWidth = texture . width * this . gameObject . mScaleX ;
4040 let desiredHeight = texture . height * this . gameObject . mScaleY ;
4141
42- // TODO: fix cache bug
43- // if (this.sizeWidthCache === desiredWidth && this.sizeHeightCache === desiredHeight) {
44- // return this.sliceTextureCache;
45- // }
42+ if ( this . sizeWidthCache === desiredWidth && this . sizeHeightCache === desiredHeight ) {
43+ return this . sliceTextureCache ;
44+ }
4645
4746 this . sizeWidthCache = desiredWidth ;
4847 this . sizeHeightCache = desiredHeight ;
@@ -61,14 +60,8 @@ class SpriteRendererCanvas extends Renderer {
6160 this . sliceTextureCache . resize ( desiredWidth , desiredHeight , 1 / texture . scale ) ;
6261
6362 const ctx = this . sliceTextureCache . renderTarget . context ;
64-
65- const data = this . gameObject . worldTransformation . data ;
6663 const scale = Math . min ( this . gameObject . scaleX , this . gameObject . scaleY ) ;
6764
68- const m = Matrix . pool . get ( ) . set ( data [ 0 ] / this . gameObject . scaleX , data [ 1 ] / this . gameObject . scaleX , data [ 2 ] / this . gameObject . scaleY , data [ 3 ] / this . gameObject . scaleY , data [ 4 ] , data [ 5 ] ) ;
69- driver . setTransform ( m ) ;
70- Matrix . pool . release ( m ) ;
71-
7265 if ( scale <= 1 ) {
7366 ctx . setTransform ( scale , 0 , 0 , scale , 0 , 0 ) ;
7467 desiredWidth /= scale ;
@@ -181,8 +174,14 @@ class SpriteRendererCanvas extends Renderer {
181174
182175 let texture = Renderer . getColoredTexture ( gameObject . mTexture , this . color ) ;
183176
184- if ( gameObject . mSlice9grid !== null )
177+ if ( gameObject . mSlice9grid !== null ) {
178+ const data = this . gameObject . worldTransformation . data ;
179+ const m = Matrix . pool . get ( ) . set ( data [ 0 ] / this . gameObject . scaleX , data [ 1 ] / this . gameObject . scaleX , data [ 2 ] / this . gameObject . scaleY , data [ 3 ] / this . gameObject . scaleY , data [ 4 ] , data [ 5 ] ) ;
180+ driver . setTransform ( m ) ;
181+ Matrix . pool . release ( m ) ;
182+
185183 texture = this . renderSlice9Grid ( driver , texture , gameObject . mSlice9grid ) ;
184+ }
186185
187186 if ( gameObject . mTiling === null ) {
188187 driver . drawTexture ( Renderer . getColoredTexture ( texture , this . color ) ) ;
@@ -213,4 +212,4 @@ class SpriteRendererCanvas extends Renderer {
213212 ctx . fillRect ( - gameObject . tiling . wrapX , - gameObject . tiling . wrapY , gameObject . tiling . width / gameObject . tiling . scaleX , gameObject . tiling . height / gameObject . tiling . scaleY ) ;
214213 }
215214 }
216- }
215+ }
0 commit comments