Book Image

Game Development with Swift

By : Stephen Haney
Book Image

Game Development with Swift

By: Stephen Haney

Overview of this book

Table of Contents (18 chapters)
Game Development with Swift
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Granting safety as the game starts


You may have noticed that Pierre Penguin quickly falls to the ground as soon as you launch the game, which is not much fun. Instead, we can launch Pierre into a graceful looping arc as the game starts to give the player a moment to prepare for flight. To do so, open Player.swift and add this code at the bottom of the spawn function:

// Grant a momentary reprieve from gravity:
self.physicsBody?.affectedByGravity = false
// Add some slight upward velocity:
self.physicsBody?.velocity.dy = 50
// Create a SKAction to start gravity after a small delay:
let startGravitySequence = SKAction.sequence([
    SKAction.waitForDuration(0.6),
    SKAction.runBlock {
        self.physicsBody?.affectedByGravity = true
    }])
self.runAction(startGravitySequence)