Enemy dies

When I collide with an enemy, I want the enemy to have a death sprite and then delete. But its not working how I want it to. Enemy just disappears!

Try this:

Note that the Player can, for example if it has the Platformer behavior, walk even if the animation is = 2, because it’s just another animation. If you want to deactivate the Player control while it’s dying (animation 2), in the same event you switch to animation 2, deactivate the Platformer behavior for the Player :wink:

Unfortunately it just deletes the object without playing the animation :frowning:

Check it out here yo. I tried. Unless there is something i’m missing.
I went over it several times. It’s just deletes the Enemy.
Unfortunately it just deletes the object without playing the animation :frowning:

What is the delay between frames for the death animation? If it is too short it will be finished before you see it.

If you just want to display a dead body sprite for a bit, you could add a second frame to the death animation that is identical to the first and then set the “time between frames” to 2 seconds.

If you want to do a fade out you can link the opacity of the death sprite to TimeDelta().

In event 5 move the delete action to event 6 and replace it with: Do -100*TimeDelta() to the opacity of Enemy
You can find opacity controls in Sprite>Visibility.

Then for event 6 have the condition: The opacity of Enemy is =0.

MattLB, Genius! I used the time between frames to 2. It works.

Please explain what -100*TimeDelta() is about.

It’s working flawlessly.
Here’s the code:

1 Like

I don’t completely understand TimeDelta(), but it’s a sort of internal timer that can be used to increase or decrease variables in the game in terms of seconds of time. You can think of it as a way of changing a value of something else by 1 every second.

For fading something out you want to make a value smaller, so that line subtracts a value from the opacity of the Enemy (which starts at 255). If you just subtracted TimeDelta() then every second it would subtract 1 from the opacity, but that would take 255 seconds to fade out. Multiplying by the 100 means it goes more quickly.

In effect, you deduct 100 during the first second, another 100 during the second second and the last 55 in the third second, so it fades out over about 2.5 seconds.