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

Features of Sprite Kit


Sprite Kit provides many features to facilitate the development of a game. These features can be used for enhancing the experience as well as performance of the game. Let's discuss them in brief.

Particle editor

This feature was introduced in iOS 7. Particle editor is used to add special effects in a game, like adding a mist effect in a game scene. Here, we can customize many things, such as:

  • The number of particles

  • Limit of particles allowed

  • The color of particles

  • The size of a particle

  • The life of a particle

  • The location of a particle in a scene, and so on

Texture atlas generator

Texture atlas generator combines all image files into one or more large images, in order to improve performance. We will discuss this in detail in the later chapters. It is recommended to use a lesser number of images to reduce draw calls (number of images rendering on a scene).

Shaders

Shaders were introduced in iOS 8. They are used to produce a variety of special effects; they calculate rendering effects on graphic hardware with a high degree of flexibility, for example, we have seen ripple effects in many apps/games. Wherever a user touches the screen, a ripple effect will be produced.

In Sprite Kit, shaders are represented by the SKShaderNode class object.

Lighting and shadows

Lighting and shadows were introduced in iOS 8. These effects are produced using the SKLightNode class object. The SKLightNode object can:

  • Spread a lighting effect at any desirable position on the scene

  • Add lighting in any sprite

  • Support colors and shadows

It's just a type SKNode, so we can apply any property that we apply to any SKNode.

Physics

Simulating physics in Sprite Kit can be achieved by adding physics bodies to the scenes. A physics engine has the sole purpose of moving objects around in a simulated world. The physics bodies take the properties of objects, such as mass, shape material, current trajectory, and so on, and calculate a new position for all those objects.

Every object on the Sprite Kit game scene will have a physics body. A physics body object is connected to a node on the node tree of a particular scene. The scene will simulate the effect of forces and collisions on those particular physics bodies that are connected to the node tree, whenever the scene computes a new frame of animation. We can apply a particular physics property on those nodes using their particular physics properties such as gravity, mass, force, friction, and so on.

The game loop

Following is a frame life cycle diagram:

At the start, the update function is called to where we set up the logic of the game. After that, the scene evaluates the actions. After the actions are evaluated, we get a callback. After that, we set up physics, if any. When the physics simulation is finished, we get another call with didSimulatePhysics. Then, we apply constraint and get another callback, didApplyConstraints. The last callback method is didFinishUpdate; we get it just before frame is completed and view is ready to render. Finally SKView renders the scene; the frame is complete and it continues 60 times per second.