Problems playing animation with msg.post (SOLVED)

I am very new to Defold and I am trying to play an animation using msg.post.

If I set the Playback property to anything other than None in design time, the animation will work. However, if I set the Playback to None and try to start the animation in my scripts Init(), it doesn’t work…

Here is the project structure:

  • I have fire.atlas which contains anim animation with 3 images
  • fire.collection contains 16 game objects (fire01, etc) and a sprite in it. It also contains go game object containing my script where the init is called to start the animation
  • main.collection contains fire.collection

The init() function contains only the function call:

msg.post("main:/fire/fire05#sprite", "play_animation", {id = hash("anim")})

I don’t see an error, so I believe the message is being delivered, but I can’t understand why it is not animating…

If there is something else I need to provide to make it clear, please let me know.

Thanks

Paulo

Is the animation set to loop or play only once? Could it be that it plays so fast that you do not notice it?

What if you add a script to one (or all) of the fire0x game objects and in init() do a msg.post("#sprite", "play_animation", {id = hash("anim")})?

Maybe provide a screenshot of the Project Outline for the fire.collection so that there is no question of how you’ve structured things?

Hi britzl,

I set the animation playback property to “None” in design time. My assumption is that I have to do that in order to play it in runtime only. If I am wrong what is the best approach to make the animation not play on startup but only after a certain condition (in my code) ?

I added the msg.post("#sprite", "play_animation", {id = hash("anim")}) command to a script under the fire01 game object and the effect is the same…

I am sure I am missing something important here, but I can’t figure out what :slight_smile:

If that helps, here are my project configuration:

Main project:

Fire atlas:

Main collection:

Fire collection:

Thanks again!

Paulo

Ah, set a default animation to a single image that will act as your “idle” or no animation. Then change from None to Once Forward or Loop Forward or whatever is suitable for your animation.

1 Like

Excellent! That was it.

After I set the default animation I managed to start the other one that actually animates the flames.

Thanks!

Paulo