[SOLVED] Animated sprite not showing up

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

Hi @smokys,

I think this can be done when the Anim State Graph comes?

(Have you done a code for it?)

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

1 Like

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?

Hi @smokys,

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.

Hi @smokys,

Have you tried adding a Sprite component and selecting Animated as type? Animated sprites are supported only on animated sprite components right now:

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.

Hi @smokys,

2D screens will only show objects with the element component. Unfortunately, the element component does not work with animated sprites.

2 Likes

Can you please show the way you did it? I was thinking of changing a frame every 200ms for example on the Image element.

Hi @smokys,

I slapped together a tiny demo of how I typically handle animation in an image element:

https://playcanvas.com/project/778517/overview/animated-2d-sprite

I hope this is helpful.

2 Likes

Thank you, @eproasim!

It is working, although acting a little weird, this is ingame frame: image

and this is frame in preview: image

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

Hi @smokys,

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.

3 Likes

Yes, that was totally it! Thank you again it is solved now, topic can be locked.

2 Likes