Animations for damage and game over

We will use SKAction sequences to create fun animations when the player takes damage. By combining actions, we will grant temporary safety after the player hits an enemy and is in a damaged state. We will show a fade animation that slowly pulses at first and then speeds up as the safe state starts to wear off.

The damage animation

To add the new animation, add this code at the bottom of the Player class' createAnimations function:

// --- Create the taking damage animation --- let damageStart = { // Allow the penguin to pass through enemies: self.physicsBody?.categoryBitMask = PhysicsCategory.damagedPenguin.rawValue } // Create an opacity pulse, slow at first and fast at the end: let slowFade = SKAction.sequence([ ...

Get Swift Game Development - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.