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 init
function:
// Grant a momentary reprieve from gravity: self.physicsBody?.affectedByGravity = false // Add some slight upward velocity: self.physicsBody?.velocity.dy = 80 // Create a SKAction to start gravity after a small delay: let startGravitySequence = SKAction.sequence([ SKAction.wait(forDuration: 0.6), SKAction.run { self.physicsBody?.affectedByGravity = true }]) self.run(startGravitySequence)