Book Image

Swift 3 Game Development - Second Edition

By : Stephen Haney
Book Image

Swift 3 Game Development - Second Edition

By: Stephen Haney

Overview of this book

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.
Table of Contents (20 chapters)
Swift 3 Game Development - Second Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Examining the demo code


Let's quickly explore the demo code. Do not worry about understanding everything just yet; we will cover each element in depth later. At this point, I am hoping you will acclimatize to the development environment and pick up a few things along the way. If you are stuck, keep going! Things will actually get simpler in the next chapter, once we clear away the SpriteKit demo and start on our own game.

Make sure you have GameScene.swift open in Xcode.

The demo GameScene class implements some functions you will use in your games. Let's examine these functions. Feel free to read the code inside each function, but I do not expect you to understand the specific code just yet.

  • The game invokes the didMove function whenever it switches to the GameScene. You can think of it a bit like an initialize, or main, function for the scene. The SpriteKit demo uses it to draw the Hello, World text to the screen and set up the spinning square shape that shows up when we tap.

  • There are seven functions involving touch which handle the user's touch input to the iOS device screen. The SpriteKit demo uses these functions to spawn the spinning square wherever we touch the screen. Do not worry about understanding these functions at this time.

  • The update function runs once for every frame drawn to the screen. The SpriteKit demo does not use this function, but we may have reason to implement it later.