Book Image

iOS Game Development By Example

By : Samanyu Chopra
Book Image

iOS Game Development By Example

By: Samanyu Chopra

Overview of this book

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 approach An 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.
Table of Contents (17 chapters)
iOS Game Development By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Elements of Sprite Kit


Now we are going to discuss some elements of Sprite Kit, which are essential for game development. A game made in Sprite Kit consists of many scenes which are made of nodes, and the functioning of a node in a scene is determined by actions.

Scenes

A level or environment in a game is termed as a scene. We make scenes as per our requirement, such as menus, levels, and so on. So, there are different scenes for different levels and also for different menus in a game. It's like a canvas where you position your elements.

A scene in Sprite Kit is represented by an SKScene object. A scene holds sprites and other contents to be rendered. To switch scenes, we can use the SKTransition class.

Nodes

Nodes are fundamental building blocks for all content in a scene. The SKScene class is a descendant of the SKNode class, so a scene is a root node. The SKNode class does not draw anything on scene by itself; we can think of it as a base class for other node classes. There are node subclasses as follows:

  • SKSpriteNode: This can be used for drawing textured sprites, playing video content, and more

  • SK3DNode: This can be used for rendering a Scene Kit scene as a 2D textured image

  • SKVideoNode: This can be used for playing video content

  • SKLabelNode: This can be used for rendering a text string

  • SKShapeNode: This can be used for rendering shape, based on a core graphics path

  • SKEmitterNode: This can be used for creating and rendering particles

  • SKCropNode: This can be used for cropping child nodes using a mask

  • SKEffectNode: This can be used for applying a core image filter to its child node

  • SKLightNode: This can be used for applying lighting and shadows to a scene

  • SKFieldNode: This can be used for applying physics effects to a specific portion of the scene

Actions

An action tells a node what to do and allows you to perform different things, such as:

  • Moving nodes in any direction

  • Making any node follow a path

  • Rotating nodes

  • Scaling of nodes

  • Showing or hiding a node

  • Changing the content of a sprite node

  • Playing sound

  • Removing nodes from a scene

  • Performing action on a child's node, and so on

To create a run action, first, create the action using the particular action class, configure the properties for the created action, and call a run action by passing action object as a parameter. When the scene processes the node, the actions of that particular node will be executed.