Looping animations after an animation has already started


Hello all,

I hope that everyone is well, I come to you with what I hope is a super quick questions. I want my character to attack, this will have a factory create the projectile. This projectile has a flipbook animation showing it increase in size. When it is at full size (in other words, when it is done with the animation) I want to to then switch to another animation group. I couldn’t quite figure out how to do this with animation_done since the factory was created through the player script. Here is my code…

if message.id == hash("attack") and message.released and facingright and onground and canattack then
		print("attack recieved")
		local pos = go.get_position() + vmath.vector3(160, 30, 0) 
		local id = factory.create("#attack", pos)
		go.animate(id, "position.x", go.PLAYBACK_ONCE_FORWARD, pos.x + 1000, go.EASING_LINEAR, 0.8, 0, function()
		canattack = false
		timer.delay(.5, false, function() canattack = true end)

Any insight would be appreciated, if I need to reword anything, please let me know!

All the best,



I’m not entirely sure I understand what you mean by this.

A finished sprite flipbook animation will generate an animation_done message on the game object the sprite is attached to. You can also use sprite.play_flipbook() and use a callback function which will get invoked when the animation is finished:

sprite.play_flipbook("#sprite", "explode", function()
    sprite.play_flipbook("#sprite", "smoke")


Thanks for your reply,

I think that I will take a look into this, it seems a bit more straightforward for me needs. For future reference, what is the applicational difference between go.animate and sprite.play_flipbook?

Thanks so much!



The go.animate() interpolates between two floating point values (or 8 for a vector4), using an easing curve.

sprite.play_flipbook() is way more specific, since the data it operates on is a lot more complex than a floating point number.



In your original post you wrote “flipbook animation” and “animation group”. Both of these concepts relate to sprite flipbook animations:

https://defold.com/manuals/animation/#flip-book-animation https://defold.com/manuals/atlas/#creating-an-atlas

go.animate() is used for property animations, which basically means animating a property such as position or rotation from one value to another over a period of time while applying an easing/tween function:



Thank you for this information, I will definintly get into the habit of using sprite.play_flipbook.

Sorry about this, I was using the totally incorrect terminology!

This is super useful info, thank you both so much for your time!