@@ -11,20 +11,23 @@ export default class RenderedUnknownInstance extends RenderedInstance {
1111 constructor (
1212 project : gdProject ,
1313 instance : gdInitialInstance ,
14- associatedObjectConfiguration : gdObjectConfiguration ,
14+ associatedObjectConfiguration : gdObjectConfiguration | null ,
1515 pixiContainer : PIXI . Container ,
1616 pixiResourcesLoader : Class < PixiResourcesLoader >
1717 ) {
1818 super (
1919 project ,
2020 instance ,
21+ //$FlowFixMe It's ok because RenderedUnknownInstance don't use it.
2122 associatedObjectConfiguration ,
2223 pixiContainer ,
2324 pixiResourcesLoader
2425 ) ;
2526
2627 //This renderer show a placeholder for the object:
27- this . _pixiObject = new PIXI . Graphics ( ) ;
28+ this . _pixiObject = new PIXI . Sprite (
29+ this . _pixiResourcesLoader . getInvalidPIXITexture ( )
30+ ) ;
2831 this . _pixiContainer . addChild ( this . _pixiObject ) ;
2932 }
3033
@@ -42,21 +45,34 @@ export default class RenderedUnknownInstance extends RenderedInstance {
4245 }
4346
4447 update ( ) {
45- const width = this . getWidth ( ) ;
46- const height = this . getHeight ( ) ;
47-
48- this . _pixiObject . clear ( ) ;
49- this . _pixiObject . beginFill ( 0x0033ff ) ;
50- this . _pixiObject . lineStyle ( 1 , 0xffd900 , 1 ) ;
51- this . _pixiObject . moveTo ( - width / 2 , - height / 2 ) ;
52- this . _pixiObject . lineTo ( width / 2 , - height / 2 ) ;
53- this . _pixiObject . lineTo ( width / 2 , height / 2 ) ;
54- this . _pixiObject . lineTo ( - width / 2 , height / 2 ) ;
55- this . _pixiObject . lineTo ( - width / 2 , - height / 2 ) ;
56- this . _pixiObject . endFill ( ) ;
57-
58- this . _pixiObject . position . x = this . _instance . getX ( ) + width / 2 ;
59- this . _pixiObject . position . y = this . _instance . getY ( ) + height / 2 ;
60- this . _pixiObject . angle = this . _instance . getAngle ( ) ;
48+ // Avoid to use _pixiObject after destroy is called.
49+ // It can happen when onRemovedFromScene and update cross each other.
50+ if ( ! this . _pixiObject ) {
51+ return ;
52+ }
53+ const objectTextureFrame = this . _pixiObject . texture . frame ;
54+ // In case the texture is not loaded yet, we don't want to crash.
55+ if ( ! objectTextureFrame ) return ;
56+
57+ this . _pixiObject . anchor . x = 0.5 ;
58+ this . _pixiObject . anchor . y = 0.5 ;
59+ this . _pixiObject . rotation = RenderedInstance . toRad (
60+ this . _instance . getAngle ( )
61+ ) ;
62+ this . _pixiObject . scale . x = this . getWidth ( ) / objectTextureFrame . width ;
63+ this . _pixiObject . scale . y = this . getHeight ( ) / objectTextureFrame . height ;
64+ this . _pixiObject . position . x = this . _instance . getX ( ) + this . getCenterX ( ) ;
65+ this . _pixiObject . position . y = this . _instance . getY ( ) + this . getCenterY ( ) ;
66+
67+ // Do not hide completely an object so it can still be manipulated
68+ const alphaForDisplay = Math . max ( this . _instance . getOpacity ( ) / 255 , 0.5 ) ;
69+ this . _pixiObject . alpha = alphaForDisplay ;
70+
71+ this . _pixiObject . scale . x =
72+ Math . abs ( this . _pixiObject . scale . x ) *
73+ ( this . _instance . isFlippedX ( ) ? - 1 : 1 ) ;
74+ this . _pixiObject . scale . y =
75+ Math . abs ( this . _pixiObject . scale . y ) *
76+ ( this . _instance . isFlippedY ( ) ? - 1 : 1 ) ;
6177 }
6278}
0 commit comments