Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Swift Game Development

You're reading from   Swift Game Development Learn iOS 12 game development using SpriteKit, SceneKit and ARKit 2.0

Arrow left icon
Product type Paperback
Published in Sep 2018
Publisher Packt
ISBN-13 9781788471152
Length 434 pages
Edition 3rd Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Siddharth Shekar Siddharth Shekar
Author Profile Icon Siddharth Shekar
Siddharth Shekar
Stephen Haney Stephen Haney
Author Profile Icon Stephen Haney
Stephen Haney
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Preface 1. Designing Games with Swift 2. Sprites, Camera, Action! FREE CHAPTER 3. Mix in the Physics 4. Adding Controls 5. Spawning Enemies, Coins, and Power-Ups 6. Generating a Never-Ending World 7. Implementing Collision Events 8. Polishing to a Shine – HUD, Parallax Backgrounds, Particles, and More 9. Adding Menus and Sounds 10. Standing out in the Crowd with Advanced Features 11. Introduction to SceneKit 12. Choosing a Monetization Strategy 13. Integrating with Game Center 14. Introduction to Spritekit with ARKit 15. Introduction to Scenekit with ARKit 16. Publishing the Game on the App Store 17. Multipeer Augmented Reality Other Books You May Enjoy Index

Setting up your development environment

Learning a new development environment can be a roadblock. Luckily, Apple provides some excellent tools for iOS developers. We will start our journey by installing Xcode.

Introducing and installing Xcode

Xcode is Apple's integrated development environment (IDE). You will need Xcode to create your game projects, write and debug your code, and build your project for the App Store. Xcode also comes bundled with an iOS simulator to test your games on virtualized iPhones and iPads on your computer.

Apple praises Xcode as "an incredibly productive environment for building amazing apps for Mac, iPhone, and iPad".

To install Xcode, search for Xcode in the App Store, or visit http://developer.apple.com, select Developer, and then Xcode.

Swift is continually evolving and each new Xcode release brings changes to Swift. If you run into errors because Swift has changed, you can always use Xcode's built-in syntax update tool. Simply use Xcode's Edit | Convert to Latest Syntax option to update your code.

Xcode performs common IDE features to help you write better, faster code. If you have used IDEs in the past, then you are probably familiar with auto completion, live error highlighting, running and debugging a project, and using a project manager pane to create and organize your files. However, any new program can seem overwhelming at first. We will walk through some common interface functions over the next few pages. I have also found tutorial videos on YouTube to be particularly helpful if you are stuck. Most common search queries result in helpful videos.

Creating our first Swift game

Do you have Xcode installed? Let's see some game code in action in the simulator!

We will start by creating a new project in Xcode. For our demo game, we will create a side-scrolling endless flyer featuring an astonishing flying penguin named Pierre. I am going to name this project Pierre Penguin Escapes the Antarctic, but feel free to name your project whatever you like. Follow these steps to create a new project in Xcode:

  1. Launch Xcode and select Create a new Xcode project:
    Creating our first Swift game
  2. You will see a screen asking you to select a template for your new project. Select iOS and Game in the pane. It should look like this:
    Creating our first Swift game
  3. Once you have selected Game, click Next. The following screen asks us to enter some basic information about our project. Don't worry; we are almost at the fun bit. Fill in the Product Name field with the name of your game:
    Creating our first Swift game
  4. Let's fill in the Team field. Do you have an active Apple Developer account? If not, you can skip over the Team field for now. If you do, your Team is your Developer account. Click Add Team and Xcode will open the Accounts screen, where you can log in. Enter your Developer credentials, as shown in the following screenshot:
    Creating our first Swift game
  5. Once you're authenticated, you can close the Accounts screen. Your Developer account should appear in the Team dropdown.
  6. You will want to pick a meaningful Organization Name and Organization Identifier when you create your own games for publication. Your Organization Name is the name of your game development studio. For me, that is Joyful Games. By convention, your Organization Identifier should follow a reverse domain name style. I will use com.growlgamesstudio since my website is growlgamesstudio.com.
  7. After you have filled out the name fields, be sure to select Swift for Language, SpriteKit for Game Technology, and Universal for Devices.
  8. For now, uncheck Integrate GameplayKit, uncheck Include Unit Tests, and uncheck Include UI Tests. We will not use these features in our demo game. Here are my final project settings:
    Creating our first Swift game
  9. Click Next and you will see the final dialog box. Save your new project. Pick a location on your computer and click Next. And we are in! Xcode has pre-populated our project with a basic SpriteKit template.

Navigating our project

Now that we have created our project, you will see the project navigator on the left-hand side of Xcode. You will use the project navigator to add, remove, and rename files and generally organize your project. You might notice that Xcode has created quite a few files in our new project. We will take it slow; don't feel that you have to know what each file does yet, but feel free to explore them if you are curious:

Navigating our project
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime