March 24, 2021, 12:09pm
Hello guys im trying to create animated sprite on my 2D screen next to the number of coins picked.
I created animated sprite in editor:
Created animated sprite and put the animation into.
I tried to put animated either in 2D screen and also in root, tried several more places but without any result. Also checked few topics how to set them but i still coulld not figure it out. any simple steps that need to be done in order to make it work? Thank you
I think this can be done when the Anim State Graph comes?
The PlayCanvas team are excited to announce the closed beta of the Anim State Graph!
This feature gives much more control of animations and transitions via a state machine via the use of parameters and conditions.
[anim state graph editor 2]
We are looking to get more feedback from the wider community and invite developers to signup to the beta. If you are interested, please reply to this thread with your PlayCanvas username.
Once Engine 1.40.0 is released and the API becomes public,…
(Have you done a code for it?)
March 24, 2021, 12:17pm
well, i checked few topic and it seemed that people figured it out somehow, i can create “animation” through code too but i was looking for non-code way. something more simple
Well, I haven’t done it the non-code way because I only know how to do it the code way. So, you can try and do this.
Put the animation on the coin then try code it together to see if it works?
As far as I know animated sprites are not supported on 2D screens at this time. The closest you can get to it is to tween the spriteframe on an image element. I hope that is helpful.
Have you tried adding a Sprite component and selecting
Animated as type? Animated sprites are supported only on animated sprite components right now:
March 24, 2021, 1:14pm
I tried to add it like this:
Its child of 2D Screen, now i see preview and also in editor i see the sprite on screen, but when i start the game there is nothing on a screen.
2D screens will only show objects with the element component. Unfortunately, the element component does not work with animated sprites.
March 24, 2021, 1:30pm
Can you please show the way you did it? I was thinking of changing a frame every 200ms for example on the Image element.
I slapped together a tiny demo of how I typically handle animation in an image element:
I hope this is helpful.
March 24, 2021, 4:27pm
It is working, although acting a little weird, this is ingame frame:
and this is frame in preview:
Its thicker ingame than in preview.
My coin has 8 frames, is there something i should change? As your example is adapted to your coin and frames
This is likely an issue with your texture atlas. If you take a look at the texture atlas in the project I linked and the frames setup inside, you will see that the frames are all the same size. This will prevent Playcanvas from attempting to stretch the frame to match the size of the image element.
March 24, 2021, 9:19pm
Yes, that was totally it! Thank you again it is solved now, topic can be locked.