iOS Game Development By Example
()
About this ebook
Learn how to develop an ace game for your iOS device, using Sprite Kit
About This Book- Learn about the Sprite Kit engine and create games on the iOS platform from the ground up
- Acquaint your Sprite Kit knowledge with Swift programming and turn your 2D game conceptualization into reality in no time
- An abridged and focused guide to develop an exhaustive mobile game
This book is for beginners who want to start their game development odyssey in the iOS platform. If you are an intermediate or proficient game developer hailing from a different development platform, this book will be a perfect gateway to the Sprite Kit engine. The reader does not need to have any knowledge of Sprite Kit and building games on the iOS platform.
What You Will Learn- Learn about the Sprite Kit game engine and create indie games in no time
- Set sail on the quest of game development career by successfully creating a runner game
- Know more about the IDE provided by Apple for game development – Xcode
- Get an overview of Apple's latest programming language, Swift
- Discover the functionalities of scenes and nodes in a game
- Explore how physics bodies work and how to add this feature into your game
- Grasp knowledge of particle effect and shaders
- Add a scoring system into your game to visualize high scores
Game development has always been an exciting subject for game enthusiasts and players and iOS game development takes a big piece of this cake in terms of perpetuating growth and creativity. With the newest version of iOS and Sprite Kit, comes a series of breathtaking features such as Metal rendering support, camera nodes, and a new and improved Scene Editor.
Conceptualizing a game is a dream for both young and old. Sprite Kit is an exciting framework supported by Apple within the iOS development environment. With Sprite Kit, creating stunning games has become an easy avenue.
Starting with the basics of game development and swift language, this book will guide you to create your own fully functional game. Dive in and learn how to build and deploy a game on your iOS platform using Sprite Kit game engine.
Go on a detailed journey of game development on the iOS platform using the Sprite Kit game engine. Learn about various features implemented in iOS 8 that further increase the essence of game development using Sprite Kit. Build an endless runner game and implement features like physics bodies, character animations, scoring and other essential elements in a game. You will successfully conceive a 2D game along with discovering the path to reach the pinnacle of iOS game development.
By the end of the book, you will not only have created an endless runner game but also have in-depth knowledge of creating larger games on the iOS platform.
Style and approachAn easy-to-follow, comprehensive guide that makes your learning experience more intriguing by gradually developing a Sprite Kit game. This book discusses each topic in detail making sure you attain a clear vision of the subject.
Samanyu Chopra
Samanyu Chopra is a developer, entrepreneur, and game developer with a bank of experience in conceptualizing, developing, and producing computer and mobile software. He has been programming since the age of 11. He is proficient in programming languages such as JavaScript, Scala, C#, C++, Swift, and so on. He has a wide range of experience in developing for computers and mobiles. He has worked on a majority of game engines and mobile platforms, and also has a strong proficiency in the Scala programming language. He is the cofounder and CEO of Daphnis Labs, a mobile app and game development studio. He has experience in managing development, leading the tech jargon, and has published over 150 apps and games for himself and his clients. In his studio, he leads a team of more than 20 members. He is known for executing eccentric projects in the app and game development spaces. He also conducts mobile development workshops at various engineering institutes. He is ardent about his work, and his colleagues, students, and coworkers think of him as a very dedicated and open-minded person. He is inclined toward investing his time in the research and development of new technologies. He is an avid traveler and adventurer and a very fun-loving and eccentric personality, as described by the people around him. He has an undying love for travel, tech, and comedy. He is inspired by all the people who have made a stand on their own from scratch. He loves his family and dedicates his life to them. You can know more about Daphnis Labs at www.DaphnisLabs.com. You can write a tweet to him at @samdonly1 or find him on Facebook for any updates. You can also reach him at samanyu@DaphnisLabs.com.
Related to iOS Game Development By Example
Related ebooks
Game Development with Swift Rating: 5 out of 5 stars5/5iOS 9 Game Development Essentials Rating: 0 out of 5 stars0 ratingsSwift by Example Rating: 1 out of 5 stars1/5LibGDX Game Development By Example Rating: 0 out of 5 stars0 ratingsiOS Game Programming Cookbook Rating: 0 out of 5 stars0 ratingsUnity Virtual Reality Projects Rating: 0 out of 5 stars0 ratingsSource SDK Game Development Essentials Rating: 0 out of 5 stars0 ratingsMastering Oculus Rift Development Rating: 0 out of 5 stars0 ratingsLearning Unreal® Engine iOS Game Development Rating: 0 out of 5 stars0 ratingsUnreal Engine Game Development Cookbook Rating: 0 out of 5 stars0 ratingsUnity Multiplayer Games Rating: 5 out of 5 stars5/5Unity Animation Essentials Rating: 0 out of 5 stars0 ratingsExtending Unity with Editor Scripting Rating: 0 out of 5 stars0 ratingsUnity Game Development Scripting Rating: 0 out of 5 stars0 ratingsMastering Cocos2d Game Development Rating: 0 out of 5 stars0 ratingsLearning Android Game Development Rating: 0 out of 5 stars0 ratingsSFML Blueprints Rating: 0 out of 5 stars0 ratingsSFML Game Development By Example Rating: 0 out of 5 stars0 ratingsUnreal Engine 4 Game Development Essentials Rating: 4 out of 5 stars4/5Learning Construct 2 Rating: 0 out of 5 stars0 ratingsAugmented Reality Game Development Rating: 0 out of 5 stars0 ratingsAndroid Game Programming by Example Rating: 0 out of 5 stars0 ratingsUnity AI Programming Essentials Rating: 0 out of 5 stars0 ratingsLearning LibGDX Game Development - Second Edition Rating: 0 out of 5 stars0 ratingsHaxe Game Development Essentials Rating: 0 out of 5 stars0 ratingsBuilding an FPS Game with Unity Rating: 0 out of 5 stars0 ratingsUnity 5.x By Example Rating: 0 out of 5 stars0 ratingsUnity from Zero to Proficiency (Beginner): Unity from Zero to Proficiency, #2 Rating: 5 out of 5 stars5/5Mobile Game Design Essentials Rating: 0 out of 5 stars0 ratingsUnity from Zero to Proficiency (Proficient): Unity from Zero to Proficiency, #5 Rating: 5 out of 5 stars5/5
Computers For You
Mastering ChatGPT: 21 Prompts Templates for Effortless Writing Rating: 4 out of 5 stars4/5Storytelling with Data: Let's Practice! Rating: 4 out of 5 stars4/5Creating Online Courses with ChatGPT | A Step-by-Step Guide with Prompt Templates Rating: 4 out of 5 stars4/5Data Analytics for Beginners: Introduction to Data Analytics Rating: 4 out of 5 stars4/5Algorithms to Live By: The Computer Science of Human Decisions Rating: 4 out of 5 stars4/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5The Alignment Problem: How Can Machines Learn Human Values? Rating: 4 out of 5 stars4/5Narrative Design for Indies: Getting Started Rating: 4 out of 5 stars4/5Get Into UX: A foolproof guide to getting your first user experience job Rating: 4 out of 5 stars4/5The Unaccountability Machine: Why Big Systems Make Terrible Decisions - and How The World Lost its Mind Rating: 0 out of 5 stars0 ratingsPython for Finance Cookbook: Over 50 recipes for applying modern Python libraries to financial data analysis Rating: 0 out of 5 stars0 ratingsBlack Holes: The Key to Understanding the Universe Rating: 5 out of 5 stars5/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5How Do I Do That In InDesign? Rating: 5 out of 5 stars5/5Python for Beginners: A Crash Course to Learn Python Programming in 1 Week Rating: 0 out of 5 stars0 ratingsAdvances in Financial Machine Learning Rating: 5 out of 5 stars5/5Learn Algorithmic Trading: Build and deploy algorithmic trading systems and strategies using Python and advanced data analysis Rating: 0 out of 5 stars0 ratingsDjango Building Dynamic Website With Django : A Complete Step By Step Guide To Learn to Build Modern Web Application with a Python Rating: 0 out of 5 stars0 ratingsArtificial Intelligence: The Complete Beginner’s Guide to the Future of A.I. Rating: 4 out of 5 stars4/5Blender 3D Basics Beginner's Guide Second Edition Rating: 5 out of 5 stars5/5Learn SAP MM in 24 Hours Rating: 0 out of 5 stars0 ratingsDeep Learning with PyTorch Rating: 5 out of 5 stars5/5ITIL® 4 Essentials: Your essential guide for the ITIL 4 Foundation exam and beyond, second edition Rating: 5 out of 5 stars5/5The ChatGPT Millionaire Handbook: Make Money Online With the Power of AI Technology Rating: 4 out of 5 stars4/5
Reviews for iOS Game Development By Example
0 ratings0 reviews
Book preview
iOS Game Development By Example - Samanyu Chopra
Table of Contents
iOS Game Development By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the color images of this book
Downloading the example code
Errata
Piracy
Questions
1. An Introduction to Sprite Kit
What's new in iOS 8?
Getting to know Swift
Getting to know Sprite Kit
Advantages of Sprite Kit
Elements of Sprite Kit
Scenes
Nodes
Actions
Features of Sprite Kit
Particle editor
Texture atlas generator
Shaders
Lighting and shadows
Physics
The game loop
Setting up a project
The Hello World project
Result
Summary
2. Scenes in Sprite Kit
Device orientation in Sprite Kit
Orientation in our project
Revisiting project elements
AppDelegate.swift
GameScene.sks
GameScene.swift
GameViewController.swift
Main.storyboard
LaunchScreen.xib
Adjusting the project
What is a scene?
Coordinate system
Creating a scene
Creating a node tree
Drawing order for a node tree
Adding the first scene in our game
Adding another scene to our game
A transition from one scene to another
Setting animation play during transition
Creating transition objects
Adding transition in our game
Summary
3. Sprites
SKSpriteNode
Initializing a sprite
The properties of SKSpriteNode
Physical
Texture
centerRect
Color
Shader
Adding a sprite without using textures
Changing the color property
Changing colorBlendFactor in MenuScene
Changing the position of a sprite
Resizing a sprite
Working with texture objects
What is a texture atlas?
Preloading textures into memory
Summary
4. Nodes in Sprite Kit
All you need to know about nodes
Using the SKNode object in the game
Recognizing a node
Initializing a node
Building a node tree
Actions on a node tree
The coordinate system of a node
Other functions and properties
Creating subclasses for our Platformer game
NodeMenuScene
CropScene
ShapeScene
ParticleScene
LightScene
VideoNodeScene
Summary
5. Physics in Sprite Kit
Simulating physics in Sprite Kit
SKPhysicsBody
The initialization of volume-based physics bodies
The initialization of edge-based physics bodies
The behavior controller properties of a physics body
The physical properties of a physics body
Collision control properties and functions
Forces and impulses
The velocity of a physics body
Using GameScene.swift to add physics bodies
Summary
6. Animating Sprites, Controls, and SceneKit
Animating nodes
SKAction
Adding a single action to a node
Adding multiple actions to a node
Creating actions
Moving nodes using actions
Rotating nodes using actions
Changing the animation speed of a node
Changing the scale position of a node
Showing or hiding a node
Changing the transparency of a node
Changing the content of a sprite node
Some other important actions
Adding controls in Sprite Kit
Node tapping and clicking
Gesture recognitions (swiping in any direction, pinching, or rotating)
Moving sprites with an accelerometer
An introduction to SceneKit
Adding animations and controls in our Platformer game
Adding actions
Transiting from GameScene to MenuScene
Adding controls in our game
Summary
7. Particle Effects and Shaders
Particle effects
The SKEmitter node
Creating the particle effect
Properties for determining a particle's lifetime
Adding the particle effect in our Platformer game
Adding the code to facilitate the particle effect
Shaders
A fact about using custom shaders
The creation and initialization of new shader objects
Uniform data in shaders
Implementing shaders in the Platformer game
Summary
8. Handling Multiple Scenes and Levels
Optimizing game levels
A strategy for multiple levels
Core Data
Adding levels in our Platformer game
Adding the Level label
Adding levels
Adding the pause functionality
Adding the NODE MENU button
Summary
9. Performance Enhancement and Extras
Performance enhancement
Systemizing a game's content in the scene
Performance enhancement by preloading textures
Improving the drawing performance
Improving performance with SKActions and constraints
Improving the physics performance
Improving shape's performance
Improving effect's performance
Improving lighting performance
Measuring performance with instruments
A scoring system in a game
Adding a scoring system in our Platformer game
Creating the Score label
Incrementing the score when required
Saving the high score
Creating the scene to save the high score
Adding a textbox to save player name
Saving the player name with high score
Creating the high score board
Adding sound into a game
Adding sounds into a Sprite Kit game
Adding sound into our Platformer game
Animation frames using SKTexture
Adding the Run action texture to the player in the Platformer game
Summary
10. Revisiting Our Game and More on iOS 9
A recap on the development process of our Platformer game
Working further on the Platformer game
An introduction to Game Center
The advantages of Game Center in a game
Integrating Game Center in a game
Working with Xcode
Working with iTunes Connect
What's new in iOS 9
Summary
Index
iOS Game Development By Example
iOS Game Development By Example
Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: August 2015
Production reference: 1240815
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78528-469-4
www.packtpub.com
Cover image by Raju Mondal (<raju@daphnislabs.com>)
Credits
Author
Samanyu Chopra
Reviewers
Chady Kassouf
Joni Mikkola
Jayant Varma
Commissioning Editor
Dipika Gaonkar
Acquisition Editor
Subho Gupta
Content Development Editor
Akashdeep Kundu
Technical Editor
Tanmayee Patil
Copy Editor
Angad Singh
Project Coordinator
Milton Dsouza
Proofreader
Safis Editing
Indexer
Rekha Nair
Production Coordinator
Manu Joseph
Cover Work
Manu Joseph
About the Author
Samanyu Chopra is a developer, entrepreneur, and game developer with a bank of experience in conceptualizing, developing, and producing computer and mobile software. He has been programming since the age of 11. He is proficient in programming languages such as JavaScript, Scala, C#, C++, Swift, and so on. He has a wide range of experience in developing for computers and mobiles. He has worked on a majority of game engines and mobile platforms, and also has a strong proficiency in the Scala programming language.
He is the cofounder and CEO of Daphnis Labs, a mobile app and game development studio. He has experience in managing development, leading the tech jargon, and has published over 150 apps and games for himself and his clients. In his studio, he leads a team of more than 20 members. He is known for executing eccentric projects in the app and game development spaces. He also conducts mobile development workshops at various engineering institutes.
He is ardent about his work, and his colleagues, students, and coworkers think of him as a very dedicated and open-minded person. He is inclined toward investing his time in the research and development of new technologies.
He is an avid traveler and adventurer and a very fun-loving and eccentric personality, as described by the people around him. He has an undying love for travel, tech, and comedy. He is inspired by all the people who have made a stand on their own from scratch. He loves his family and dedicates his life to them.
You can know more about Daphnis Labs at www.DaphnisLabs.com. You can write a tweet to him at @samdonly1 or find him on Facebook for any updates. You can also reach him at
I would like to thank everyone at Packt Publishing who helped in carving this book, including my acquisition editor, Subho Gupta, content development editor, Akashdeep Kundu, technical editor, Tanmayee Patil, and especially the reviewers. Writing this book has been a remarkable experience for me and it wouldn't have been possible without their support and guidance.
I would like to thank all the mentors that I've had over the years. For this book, particularly, I would like to thank my dad, Mukul Chopra, and the iOS lead in our company, Nitin Rajashekhar, for their wisdom and support.
Finally, immense thanks to my family, friends, and team members at Daphnis Labs, who supported me in making games along with helping me teach game development to others. The conceptualization of this book is the result of the motivation and inspiration provided by them.
About the Reviewers
Chady Kassouf is an independent iOS and web development expert. He started programming 23 years ago and hasn't stopped ever since.
7 years ago, he decided to leave his job as a team leader at one of the leading digital agencies to start his own business.
His interests outside of computers include arts, music, and fitness. He can be found online at http://chady.net/.
Joni Mikkola is currently working on his next mobile game in Northern Finland. He keeps his game developing stamina up to the mark by training regularly at the gym and eating healthy. While developing games, he often reads books, plays the piano, or bakes buns to keep ideas flowing and his mind focused. He is constantly challenging the status quo, which in turn helps him learn new ways to create things.
He has developed games for over 4 years professionally, mostly for mobile platforms. He targets casual games and focuses on creating simplistic designs. With one game released, he is currently working on his next game, which will be released in late 2015 for the Android and iOS platforms.
Jayant Varma is the founder of OZ Apps (www.oz-apps.com), a consulting, training, and development company that provides IT solutions (specialization in mobile technology). He is an experienced developer with more than 20 years of industry experience in several countries. He is also the author of a number of books on iOS development, including Learn Lua for iOS Game Development, Apress. 2012, Xcode 6 Essentials, Packt Publishing. 2015, More iPhone Development with Swift, Apress. 2015, More iPhone Development with Objective-C, Apress. 2015, and Pro Bash Programming, Apress. 2015. He has been a university lecturer in Australia, where he currently resides. He loves traveling and Europe is his favorite destination.
www.PacktPub.com
Support files, eBooks, discount offers, and more
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Free access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.
Preface
Sprite Kit is a set of tools to develop 2D games for the Apple iOS platform. Sprite Kit provides powerful features for graphics and the animation of images having texture, and so on. It is one of the best available game engines for iOS devices. It is very simple and powerful, with full support provided by Apple, hence it is more reliable and convenient than any third-party game engine available today.
The Integrated Development Environment (IDE), Xcode, provided by Apple for app development can also be used for Sprite Kit game development. Objective-C or Swift, either of the two programming languages can be used for Sprite Kit game development. Sprite Kit is already being used by many developers for iOS game development. There is a good amount of information available that focuses on Sprite Kit set up and development. However, a structured and concise resource discussing about the complete development process and feature set is not currently available. This book explains the basics of Sprite Kit development and allows a beginner to become skilled in Sprite Kit game development using the Swift programming language with its complete set of development features. This book is a complete guide for Sprite Kit and a perfect starting point for those wanting to set sail on the iOS game industry.
What this book covers
Chapter 1, An Introduction to Sprite Kit, introduces you to the Sprite Kit game engine, along with its various elements and features. It also helps in setting up a new Xcode project for developing a Sprite Kit game.
Chapter 2, Scenes in Sprite Kit, explains an important topic in Sprite Kit, that is, scenes. Along with this, there is a brief about the node tree drawing order.
Chapter 3, Sprites, explains sprites and their properties. It also applies some of the properties in the example game.
Chapter 4, Nodes in Sprite Kit, discusses about nodes and its subclasses in detail. It also explains the implementation of various node subclasses in the example game.
Chapter 5, Physics in Sprite Kit, talks about physics simulation in a Sprite Kit game. It explains the types of physics bodies. Physics capabilities are applied to the example game in this chapter.
Chapter 6, Animating Sprites, Controls, and SceneKit, covers animating nodes and adding controls to a Sprite Kit game. These features are added in the example game. It also talks about SceneKit.
Chapter 7, Particle Effects and Shaders, discusses about particle effects and shaders, along with their implementation in the example game.
Chapter 8, Handling Multiple Scenes and Levels, helps us understand the need for different levels in a game. This chapter also explains how to create multiple scenes.
Chapter 9, Performance Enhancement and Extras, discusses in detail how to improve the performance of a Sprite Kit game, along with performance measuring using instruments. It also explains the scoring system, sound, and player running animation in the example game.
Chapter 10, Revisiting Our Game and More on iOS 9, discusses the various steps involved in the development of a game, and introduces readers to the Game Center and discusses new features that will be introduced in iOS 9.
What you need for this book
Readers will require Xcode, which is the IDE provided by Apple for developing software, and also the sample game for Mac OS X and iOS devices. An iOS-running device will be helpful to the readers for running the example game that is being developed in the book.
Who this book is for
This book is for beginners who want to start their game development odyssey on the iOS platform. If you are an intermediate or proficient game developer hailing from a different development platform, this book will be the perfect gateway into the