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

Adding the first scene in our game


Now it is time to add a menu scene to our game. For this, select the Platformer folder and right-click on this folder, select New File. Select iOS | Source | Swift File and then Next. Inside Save As, give it the name MenuScene, and click on Create.

Click on your MenuScene.swift file. Now it's time to do some code stuff:

import SpriteKit
class MenuScene: SKScene
{
  //#1
  let PlayButton: SKSpriteNode
  let Background: SKSpriteNode
  //#2
  init(size:CGSize, playbutton:String, background:String)
  {
    PlayButton = SKSpriteNode(imageNamed: playbutton)
    Background = SKSpriteNode(imageNamed: background)
    super.init(size:size)
  }
  //#3
  required init?(coder aDecoder: NSCoder)
  {
    fatalError("init(coder:) has not been implemented")
  }
  //#4
  override func didMoveToView(view: SKView)
  {
    addChildToScene();

  }
  //#5
  func addChildToScene()
  {
    PlayButton.zPosition = 1
    Background.zPosition = 0
    Background.size = CGSize(width:self...