Hello,
I am writing a small game and have encountered some problem. It's about playing the animation after changing the texture props. I need to change the animation for the main character depending on which key is pressed right now. However, after another texture prop is sent to the AnimatedSprite component, everything stops.
I was looking for an answer and found it on reddit: Link. So all I need is just to call the play() function, but I don't have access to the AnimationSprite instance. The AnimationSprite component cannot work with ref prop and returns null instead of an instance.
Fortunately, I found a solution: I need to provide ref prop to Container component that wraps the AnimationSprite component, after that I get a children prop of an Container instance with an instance of AnimationSprite inside and call the playback function.
In my opinion that solution is pretty dirty, so I ask you to add auto call of play() function after textures prop changed or/and add ref prop support.
In my opinion, the solution is quite dirty, so I ask you to add an automatic call to the play() function after changing the textures prop or/and and add support for the ref props.
Description
Hello, I am writing a small game and have encountered some problem. It's about playing the animation after changing the
texture
props. I need to change the animation for the main character depending on which key is pressed right now. However, after anothertexture
prop is sent to theAnimatedSprite
component, everything stops.I was looking for an answer and found it on reddit: Link. So all I need is just to call the
play()
function, but I don't have access to theAnimationSprite
instance. TheAnimationSprite
component cannot work withref
prop and returnsnull
instead of an instance.Fortunately, I found a solution: I need to provide
ref
prop toContainer
component that wraps theAnimationSprite
component, after that I get achildren
prop of anContainer
instance with an instance ofAnimationSprite
inside and call the playback function.In my opinion that solution is pretty dirty, so I ask you to add auto call of
play()
function aftertextures
prop changed or/and addref
prop support.In my opinion, the solution is quite dirty, so I ask you to add an automatic call to the
play()
function after changing thetextures
prop or/and and add support for theref
props.Steps to reproduce
It's quite easy and could be reproduced on demo codepen at that Link. I forked and made an example, where I've tried to bruteforce bug with my solution. You can see it here starting with 52 line.
So, steps are next
AnimationSprite
componenttexture
prop after first render.Additional info
@inlet/react-pixi
version: 6.8.0React
version: 17.0.2ReactDOM
version: 17.0.2PIXI
version: 6.5.8