Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
iOS Game Programming Cookbook

You're reading from   iOS Game Programming Cookbook Over 45 interesting game recipes that will help you create your next enthralling game

Arrow left icon
Product type Paperback
Published in Mar 2015
Publisher
ISBN-13 9781784398255
Length 300 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Toc

Table of Contents (14) Chapters Close

Preface 1. iOS Game Development FREE CHAPTER 2. SpriteKit 3. Animations and Texture 4. Particle System and Game Performance 5. Adding Music to iOS Games and an Introduction to iCloud 6. Physics Simulation 7. Adding Reality to Games 8. Introduction to Game Math and Physics 9. Autonomous Moving Agents 10. 3D Game Programming with OpenGL 11. Getting Started with Multiplayer Games 12. Implementing Multiplayer Games Index

Getting started with the SpriteKit game framework

With the release of iOS 7.0, Apple has introduced its own native 2D game framework called SpriteKit. SpriteKit is a great 2D game engine, which has support for sprite, animations, filters, masking, and most important is the physics engine to provide a real-world simulation for the game.

Apple provides a sample game to get started with the SpriteKit called Adventure Game. The download URL for this example project is http://bit.ly/Rqaeda.

This sample project provides a glimpse of the capability of this framework. However, the project is complicated to understand and for learning you just want to make something simple. To have a deeper understanding of SpriteKit-based games, we will be building a bunch of mini games in this book. To understand the basics of the SpriteKit game programming, we will build a mini AntKilling game in this chapter.

Getting ready

To get started with iOS game development, you have the following prerequisites for SpriteKit:

  • You will need the Xcode 5.x
  • The targeted device family should be iOS 7.0+
  • You should be running OS X 10.8.X or later

If all the above requisites are fulfilled, then you are ready to go with the iOS game development. So let's start with game development using iOS native game framework. We will be building a mini game in the chapter and will be taking it forward in every chapter to add more and more features and enhancements.

How to do it...

Let's start building the AntKilling game. Perform the following steps to create your new SpriteKit project:

  1. Start your Xcode. Navigate to File | New | Project....
    How to do it...
  2. Then from the prompt window, navigate to iOS | Application | SpriteKit Game and click on Next.
    How to do it...
  3. Fill all the project details in the prompt window and provide AntKilling as the project name with your Organization Name, device as iPhone, and Class Prefix as AK. Click on Next.
    How to do it...
  4. Select a location on the drive to save the project and click on Create.
  5. Then build the sample project to check the output of the sample project. Once you build and run the project with the play button, you should see the following on your device:
    How to do it...

How it works...

The following are the observations of the starter project:

  1. As you have seen, the sample project of SpriteKit plays a label with a background color.
  2. SpriteKit works on the concept of scenes, which can be understood as the layers or the screens of the game. There can be multiple scenes working at the same time; for example, there can be a gameplay scene, hud scene, and the score scene running at the same time in the game.

Now we can look into the project for more detail arrangements of the starter project. The following are the observations:

  1. In the main directory, you already have one scene created by default called AKMyScene.
  2. Now click on AKMyScene.m to explore the code to add the label on the screen. You should see something similar to the following screenshot:
    How it works...
  3. Now we will be updating this file with our code to create our AntKilling game in the next sections.
  4. We have to fulfill a few prerequisites to get started with the code, such as locking the orientation to landscape as we want a landscape orientation game.
  5. To change the orientation of the game, navigate to AntKilling project settings | TARGETS | General. You should see something similar to the following screenshot:
    How it works...
  6. Now in the General tab, uncheck Portrait from the device orientation so that the final settings should look similar to the following screenshot:
    How it works...
  7. Now build and run the project. You should be able to see the app running in landscape orientation.
    How it works...
  8. The bottom-right corner of the screen shows the number of nodes with the frame rate.
You have been reading a chapter from
iOS Game Programming Cookbook
Published in: Mar 2015
Publisher:
ISBN-13: 9781784398255
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
Banner background image