What is the best way to change sprites?

Hi there folks. I know of a couple of ways of changing sprites in defold, and I’m sure there are probably more ways to do it. These are the 2 I’m familiar with:

sprite.play_flipbook("#sprite", hash(“spriteName”))

msg.post("#sprite", “play_animation”, {id = hash(“spriteName”)})

I guess each has its own pros and cons depending how they’re being used. When should I favor one over the other? Also, what are the alternatives to these, and are any of them preferable in specific situations?
Thanks in advance

Both functions will result in a message being sent to the sprite component. I prefer to use sprite_playflipbook() as I get more help with auto complete plus the fact that I can set a callback function to be called when the animation has finished.

3 Likes