June 2018
Beginner to intermediate
298 pages
7h 38m
English
It's not fair if the player can't strike back, so in the tradition of Super Mario Bros., jumping on top of the enemy will defeat it.
Start by adding a new animation to the AnimationPlayer of the Enemy and name it death. Set the Length to 0.3 seconds and the Step to 0.05. Don't turn on looping for this animation.
This animation will also set the Texture and Frame. This time, drag the res://assets/enemy-death.png image into the Sprite's Texture before adding the keyframe for that property. As before, keyframe all the Frame values from 0 through 5. Press Play to see the death animation run.
Add the following code to the Enemy's script:
func take_damage(): $AnimationPlayer.play('death') $CollisionShape2D.disabled = true set_physics_process(false) ...Read now
Unlock full access