# Looping animations after an animation has already started

**URL:** <https://forum.defold.com/t/looping-animations-after-an-animation-has-already-started/65670>\
**Category:** Questions\
**Created:** [June 26, 2020, 7:08pm UTC](https://forum.defold.com/t/looping-animations-after-an-animation-has-already-started/65670 "2020-06-26T19:08:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vgreen](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/vgreen/32/13343_2.png) [@Vgreen](https://forum.defold.com/u/Vgreen)\
**Post date:** [June 26, 2020, 7:08pm UTC](https://forum.defold.com/t/looping-animations-after-an-animation-has-already-started/65670/1 "2020-06-26T19:08:02Z")

</div>

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")
		print("attackright")
		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()
			go.delete(id)
		end)
		canattack = false
		timer.delay(.5, false, function() canattack = true end)
	end

```

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

All the best,  
V

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [June 26, 2020, 8:57pm UTC](https://forum.defold.com/t/looping-animations-after-an-animation-has-already-started/65670/2 "2020-06-26T20:57:53Z")

</div>

> [@Vgreen](#):
>
> I couldn’t quite figure out how to do this with `animation_done` since the factory was created through the player script

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

> [@Vgreen](#):
>
> 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.

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")
end)

```

---

<div class="post-metadata">

**Author:** ![Vgreen](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/vgreen/32/13343_2.png) [@Vgreen](https://forum.defold.com/u/Vgreen)\
**Post date:** [June 27, 2020, 12:19am UTC](https://forum.defold.com/t/looping-animations-after-an-animation-has-already-started/65670/3 "2020-06-27T00:19:26Z")

</div>

Thanks for your reply,

> [@britzl](#):
>
> You can also use sprite.play\_flipbook() and use a callback function which will get invoked when the animation is finished:

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!

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [June 27, 2020, 6:32am UTC](https://forum.defold.com/t/looping-animations-after-an-animation-has-already-started/65670/4 "2020-06-27T06:32:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [June 27, 2020, 8:00am UTC](https://forum.defold.com/t/looping-animations-after-an-animation-has-already-started/65670/5 "2020-06-27T08:00:24Z")

</div>

> [@Vgreen](#):
>
> 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` ?

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

[Animation in Defold manual](https://defold.com/manuals/animation/#flip-book-animation) [Atlas manual](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:

> **[Animation in Defold manual](https://defold.com/manuals/animation/#property-animation)**
>
> This manual describes Defold's animation support.

---

<div class="post-metadata">

**Author:** ![Vgreen](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/vgreen/32/13343_2.png) [@Vgreen](https://forum.defold.com/u/Vgreen)\
**Post date:** [June 27, 2020, 9:26pm UTC](https://forum.defold.com/t/looping-animations-after-an-animation-has-already-started/65670/6 "2020-06-27T21:26:07Z")

</div>

> [@Mathias\_Westerdahl](#):
>
> `sprite.play_flipbook()` is way more specific, since the data it operates on is a lot more complex than a floating point number.

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

> [@britzl](#):
>
> In your original post you wrote “flipbook animation” and “animation group”. Both of these concepts relate to sprite flipbook animations:

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

> [@britzl](#):
>
> 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:

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