Swift 3 Game Development - Second Edition

Book description

Embrace the mobile gaming revolution by creating popular iOS games with Swift 3.0

About This Book

  • Create and design games for iPhone and iPad using SpriteKit and Swift 3.0
  • Learn the core fundamentals of SpriteKit game development and mix and match techniques to customize your game
  • This step-by-step practical guide will teach you to build games from scratch using little-known tips and strategies for maximum fun

Who This Book Is For

If you wish to create and publish fun iOS games using Swift, then this book is for you. You should be familiar with basic programming concepts. However, no prior game development or Apple ecosystem experience is required.

What You Will Learn

  • Deliver powerful graphics, physics, and sound in your game by using SpriteKit
  • Set up the scene using the new capabilities of the scene editor and custom classes
  • Maximize gameplay with little-known tips and strategies for fun and repeatable action
  • Make use of animations, graphics, and particles to polish your game
  • Understand the current mobile monetization landscape to choose the best option for your own situation
  • Integrate your game with Game Center so that your players can share their high scores and achievements
  • Publish your game to the App Store and enjoy people playing your games

In Detail

Swift is the perfect choice for game development. Developers are intrigued by Swift 3.0 and want to make use of new features to develop their best games yet. Packed with best practices and easy-to-use examples, this book leads you step by step through the development of your first Swift game.

This book starts by introducing SpriteKit and Swift's new features that can be used for game development. After setting up your first Swift project, you will build your first custom class, learn how to draw and animate your game, and add physics simulations.

Then, you will add the player character, NPCs, and powerups. To make your game more fun and engaging, you will learn how to set up scenes and backgrounds, build fun menus, and integrate with Apple Game Center to add leaderboards and achievements. You will then make your game stand out by adding animations when game objects collide, and incorporate proven techniques such as the advanced particle system and graphics. Finally, you will explore the various options available to start down the path towards monetization and publish your finished games to the App Store.

By the end of this book, you will be able to create your own iOS games using Swift and SpriteKit.

Style and approach

This project-based guide is engaging with a visually-rich approach rather than a text-heavy approach. With every chapter containing practical examples, you will understand how Swift programming works and make the most of the new features in version 3.0.

Table of contents

  1. Swift 3 Game Development - Second Edition
    1. Swift 3 Game Development - Second Edition
    2. Credits
    3. About the Author
    4. About the Reviewer
    5. www.PacktPub.com
      1. Why subscribe?
    6. Customer Feedback
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    8. 1. Designing Games with Swift
      1. Why you will love Swift
      2. Prerequisites
      3. What you will learn in this book
        1. Embracing SpriteKit
        2. Reacting to player input
        3. Structuring your game code
        4. Building UI/menus/levels
        5. Integrating with Game Center
        6. Maximizing fun
        7. Crossing the finish line
        8. Monetizing your work
      4. New in Swift 3
      5. Setting up your development environment
        1. Introducing and installing Xcode
        2. Creating our first Swift game
        3. Navigating our project
      6. Exploring the SpriteKit demo
      7. Examining the demo code
      8. Cleaning up
      9. Summary
    9. 2. Sprites, Camera, Action!
      1. Sharpening our pencils
      2. Checkpoint 2-A
      3. Drawing your first sprite
      4. Building a SKSpriteNode class
      5. Adding animation to your toolkit
        1. Sequencing multiple animations
        2. Recapping your first sprite
      6. The story on positioning
        1. Alignment with anchor points
      7. Adding textures and game art
        1. Downloading the free assets
        2. More exceptional art
        3. Drawing your first textured sprite
        4. Adding the bee image to your project
        5. Loading images with SKSpriteNode
      8. Designing for retina
        1. The ideal asset approach
        2. Hands-on with retina in SpriteKit
      9. Organizing your assets
        1. Exploring Assets.xcassets
        2. Collecting art into texture atlases
        3. Updating our bee node to use the texture atlas
        4. Iterating through texture atlas frames
        5. Putting it all together
      10. Centering the camera on a sprite
      11. Checkpoint 2-B
      12. Summary
    10. 3. Mix in the Physics
      1. Laying the foundation
        1. Following protocol
        2. Reinventing the bee
        3. The icy tundra
          1. Adding the ground texture to Assets.xcassets
          2. Adding the Ground class
          3. Tiling a texture
          4. Running wire to the ground
        4. A wild penguin appears!
      2. Renovating the GameScene class
      3. Exploring the physics system
        1. Dropping like flies
        2. Solidifying the ground
      4. Checkpoint 3-A
      5. Exploring physics simulation mechanics
      6. Bee meets bee
        1. Impulse or force?
      7. Checkpoint 3-B
      8. Summary
    11. 4. Adding Controls
      1. Retrofitting the Player class for flight
        1. The Beekeeper
        2. Updating the Player class
        3. Moving the ground
      2. Assigning a physics body to the player
        1. Creating a physics body shape from a texture
      3. Polling for device movement with Core Motion
        1. Implementing the Core Motion code
      4. Checkpoint 4-A
      5. Wiring up the sprite onTap events
        1. Implementing touchesBegan in the GameScene
        2. Larger than life
      6. Teaching our penguin to fly
      7. Listening for touches in GameScene
      8. Fine-tuning gravity
      9. Spreading your wings
      10. Improving the camera
      11. Pushing Pierre forward
      12. Tracking the player's progress
        1. Looping the ground
      13. Checkpoint 4-B
      14. Summary
    12. 5. Spawning Enemies, Coins, and Power-ups
      1. Introducing the cast
      2. Locating and adding the art assets
      3. Adding the Power-up Star
        1. Adding the Star class
      4. Adding a new enemy - the Mad Fly
        1. Adding the MadFly class
      5. Another terror - Bats!
        1. Adding the Bat class
      6. Guarding the ground - adding the Blade
        1. Adding the Blade class
      7. Adding the coins
        1. Creating the coin classes
      8. Organizing the project navigator
      9. Testing the new game objects
      10. Checkpoint 5-A
      11. Preparing for endless flight
      12. Summary
    13. 6. Generating a Never-Ending World
      1. Designing levels with the SpriteKit scene editor
        1. Separating level data from game logic
        2. Using custom classes in the scene editor
      2. Encounters in endless flying
        1. Creating our first encounter
        2. Integrating scenes into the game
      3. Checkpoint 6-A
      4. Spawning endless encounters
        1. Building more encounters
        2. Updating the EncounterManager class
        3. Storing metadata in SKSpriteNodeuserData property
        4. Wiring up EncounterManager in the GameScene class
      5. Spawning the Power-up Star at random
      6. Turning bronze coins to gold
      7. Checkpoint 6-B
      8. Summary
    14. 7. Implementing Collision Events
      1. Learning the SpriteKit collision vocabulary
        1. Collision versus contact
        2. Physics category masks
        3. Using category masks in Swift
      2. Adding contact events to our game
        1. Setting up the physics categories
      3. Assigning categories to game objects
        1. The player
        2. The ground
        3. The Power-up Star
        4. Enemies
        5. Coins
      4. Preparing GameScene for contact events
        1. Viewing console output
        2. Testing our contact code
      5. Checkpoint 7-A
      6. Player health and damage
      7. Animations for damage and game over
        1. The damage animation
        2. The game over animation
        3. Collecting coins
        4. The Power-up Star logicterrific progress in this chapter. To download my project up to this 
      8. Checkpoint 7-B
      9. Summary
    15. 8. Polishing to a Shine - HUD, Parallax Backgrounds, Particles, and More
      1. Adding a HUD
        1. Implementing the HUD
      2. Parallax background layers
        1. Adding the background assets
        2. Implementing a background class
        3. Wiring up backgrounds in the GameScene class
      3. Checkpoint 8-A
      4. Harnessing SpriteKit's particle system
        1. Adding the circle particle asset
        2. Creating a SpriteKit particle file
        3. Configuring the path particle settings
        4. Adding the particle emitter to the game
      5. Granting safety as the game starts
      6. Checkpoint 8-B
      7. Summary
    16. 9. Adding Menus and Sounds
      1. Building the main menu
        1. Creating the menu scene and menu nodes
        2. Launching the main menu when the game starts
        3. Wiring up the START GAME button
      2. Adding the restart game menu
        1. Extending the HUD
        2. Wiring up GameScene for game over
        3. Informing the GameScene class when the player dies
        4. Implementing touch events for the restart menu
      3. Checkpoint 9-A
      4. Adding music and sound
        1. Adding the sound assets to the game
        2. Playing background music
      5. Playing sound effects
        1. Adding the coin sound effect to the Coin class
        2. Adding the power-up and hurt sound effects to the Player class
        3. Playing a sound when the game starts
      6. Checkpoint 9-B
      7. Summary
    17. 10. Standing Out in the Crowd with Advanced Features
      1. Adding fun crates to smash open
        1. Creating the Crate particle effects
      2. Recycling emitter nodes with particle pools
      3. Checkpoint 10-A
      4. Wiring up crate contact events
      5. Adding a health crate
      6. Smashing coin crates
      7. Checkpoint 10-B
      8. Summary
    18. 11. Choosing a Monetization Strategy
      1. Developing your marketing plan
        1. When to start marketing
        2. Marketing checklist
      2. Leveraging crowdfunding
        1. Pros and cons of crowdfunding
      3. Showing display ads for revenue
        1. The upsides to showing ads
        2. The downsides to showing ads
      4. Selling in-app purchases
        1. In-app purchase strategies
        2. A word about farming your players
      5. Localization into foreign markets
      6. Managing scope and completing projects
      7. Summary
    19. 12. Integrating with Game Center
      1. Registering an app with iTunes Connect
      2. Creating a test user
      3. Authenticating the player's Game Center account
      4. Opening Game Center in our game
      5. Checkpoint 10-A
      6. Adding a leaderboard of high scores
        1. Creating a new leaderboard in iTunes Connect
        2. Updating the leaderboard from the code
      7. Adding an achievement
        1. Creating a new achievement in iTunes Connect
        2. Updating achievements from the code
      8. Checkpoint 10-B
      9. Summary
    20. 13. Ship It! Preparing for the App Store and Publication
      1. Finalizing assets
        1. Adding app icons
      2. Designing the launch screen
        1. Taking screenshots for each supported device
        2. Finalizing iTunes Connect information
        3. Configuring pricing
      3. Uploading our project from Xcode
      4. Submitting for review in iTunes Connect
      5. Summary

Product information

  • Title: Swift 3 Game Development - Second Edition
  • Author(s): Stephen Haney
  • Release date: February 2017
  • Publisher(s): Packt Publishing
  • ISBN: 9781787127753