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
iOS 9 Game development Essentials

You're reading from   iOS 9 Game development Essentials Design, build, and publish an iOS game from scratch using the stunning features of iOS 9

Arrow left icon
Product type Paperback
Published in Nov 2015
Publisher
ISBN-13 9781784391430
Length 224 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Chuck Gaffney Chuck Gaffney
Author Profile Icon Chuck Gaffney
Chuck Gaffney
Arrow right icon
View More author details
Toc

Table of Contents (10) Chapters Close

Preface 1. The Swift Programming Language 2. Structuring and Planning a Game Using iOS 9 Storyboards and Segues FREE CHAPTER 3. SpriteKit and 2D Game Design 4. SceneKit and 3D Game Design 5. GameplayKit 6. Exhibit the Metal in Your Game 7. Publishing Our iOS Game 8. The Future of iOS Game Development Index

Boolean

An integral part of all programming, game, or otherwise is the use of Boolean values. Boolean values typically return either true or false values, yes or no, or 0 or 1. In Swift, this is the job of the Bool class of objects. The use of the function .isEmpty() in our past collection data type examples returns a Boolean value of true or false based on whether that collection is empty or not.

In game development, one way we could use Boolean values is to have a global variable (a variable accessible in scope throughout our game/app) that checks if the game is over.

var isGameOver = false

This variable, taken from the PikiPop game, starts the game off with a variable of type bool named isGameOver with a starting value of false. If the events of the game cause this value to change to true, then this triggers the events associated with the game over state.

Note

Unlike Boolean values in Objective-C, Swift uses only true or false values to represent Boolean variables. Swift strict type safety does not allow the use of YES and NO or 0 and 1, as we have seen in Objective-C and other programming languages.

However, reading and controlling this type of information about our game, known as the game's state, is best controlled with more than just a single Boolean value. This is because your game and the characters in your game could have various states, such as game over, paused, spawn, idle, running, falling, and more. A special object known as a state machine best manages this type of information. State machines shall be covered in more detail when we discuss the GameplayKit framework.

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 €18.99/month. Cancel anytime