O'Reilly logo

Swift 3 Game Development - Second Edition by Stephen Haney

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 in a damaged state after the player hits an enemy. 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 = SKAction.run { // 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([ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required