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

Ints, UInts, floats, and doubles

In addition to Boolean values, another basic data type we have up to this point briefly mentioned is the various numeric objects, such as integers (Ints), unsigned integers (UInts), floating point numbers / decimals (floats), and double precision floating point numbers / decimals (doubles).

Integers and unsigned integers

Integers represent negative and positive whole numbers, while unsigned integers represent positive whole numbers. Like with C and other programming languages, Swift lets us create various types of integers and unsigned integers from 8, 16, 32, and 64 bits. For example, an Int32 type is a 32-bit integer, while a UInt8 type is an 8-bit unsigned integer. The size of the bits for Ints and UInts represents how much space is being allocated to store the values. Using our UInt8 example, a number made from this type of unsigned Int can only store the values 0-255 (or 11111111 in a base-2 system). This is also known as 1 byte (8 bits). If we need to store numbers larger than 255 or negative numbers, then maybe an Int16 type would suffice as that can store numbers between –32767 and 32767. Usually, we don't have to worry too much about the size allocated by our integer variables and constants. So, using just the class name of Int will work fine in most cases.

Note

The size of Int will differ depending on the type of system we are working on. If we are compiling our code on a 32-bit system, an integer will be equal to Int32, while the same integer would be an Int64 on a 64-bit system.

Swift can let us see what our minimum and maximum values are for an Int variable with the .min or .max class variables (that is, Int16.max = 32767 and UInt.min = 0).

Floats and doubles

Floats are 32bit floating point numbers / fractions, such as pi (3.14), or the golden ratio, phi (1.61803).

In game designing, we work with floating point values and ranges rather often, be it to determine the CGPoint in x and y of a 2D sprite, using linear interpolation for smoothing a game's camera movement in 3D space, or applying various physics forces on an object or 2D/3D vector. The precision needed for each situation will determine if a float is needed or if the 64-bit floating point value, the double is needed. Doubles can be as precise as 15 decimal places, while a float is six decimal places precise.

Tip

It's actually best practice to use doubles in situations that would work for either floats or doubles.

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