How do I get this animation to play repeatedly?

I’m trying to get this specific animation to run every single time my bullet sprite collides with my enemy sprite. It works the first time they collide but then the subsequent tries after that nothing happens.

Try a “For Each” event on the bullet object with the enemy collision conditions and actions.

Didn’t work, still only playing the animation on the first hit.

Oops, how about the for each event being put on the enemy object, not the bullet?
Sorry for the mix up.

How would I go about doing that? Do I have to create a custom function?

No, there’s a button with a big plus on it that gives you a drop down menu. You should see options to group events, link external ones, etc. You want to pick “For Each…” and then select your enemy object where it asks for an object.

In case I mangled that explanation, there’s more here:

http://wiki.compilgames.net/doku.php/gdevelop5/events
http://wiki.compilgames.net/doku.php/gdevelop5/events/foreach

Unfortunately the same thing is happening, regardless of which object I choose.

I don’t think “For Each” would solve the problem here.

Is the animation in the sprite set to Loop, or is it set to only play once?
Either way, I think the way to solve this would be to use the “Change current frame to 0” and “Play the animation” actions to re-start the animation every single time the event plays. To do that, we can use a sub-event with the “Trigger Once” condition, like this:

Sub-Event:

If true, trigger once
  do = 0 to animation frame of Player
  play the current animation of Player

This way, when the collision in the parent event is true, the actions in the sub-event will play once and will “reset” the animation. You don’t need to set it to Loop if you’re doing this.
Also, both of these actions can be found in “Sprite > Animations and Images”, and the “Trigger Once” condition can be found in “Advanced > Trigger once while true”.

I hope this helps!

3 Likes

Yay it works! Thank you so much.

2 Likes