Book Image

Learning iOS 8 Game Development Using Swift

By : Siddharth Shekar
Book Image

Learning iOS 8 Game Development Using Swift

By: Siddharth Shekar

Overview of this book

<p>Game development has been simplified with Apple's new programming language—Swift. If you're looking to start learning iOS development then you'll get everything you need - from&nbsp;the absolute basics such as the Xcode interface and takes you all the way to Swift programming.</p> <p>You will take a walk through the creation of 2D and 3D games followed by an introduction to SpriteKit and SceneKit. The book also looks at how game objects are placed in 3D scenes, how to use the graphics pipeline, and how objects are displayed on mobile screens. You will also delve into essential game concepts such as collision detection, animation, particle systems, and scene transitions. Finally, you will learn how to publish and distribute games to the iTunes store.</p>
Table of Contents (18 chapters)
Learning iOS 8 Game Development Using Swift
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Adding a SpriteKit overlay


For showing scores and buttons for the game, we will add 2D SpriteKit layer. For adding the overlay, create a class called OverlaySKscene. In this class, add the following:

import SpriteKit

class OverlaySKScene: SKScene {
    
    let _gameScene: GameSCNScene!
    let myLabel: SKLabelNode!
    var gameOverLabel: SKLabelNode!
    var jumpBtn: SKSpriteNode!
    var playBtn: SKSpriteNode!
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    init(size: CGSize, gameScene: GameSCNScene){

    super.init(size: size)
    
    }
}

To import SpriteKit we will have to create a subclass of SpriteKit. Create global variables of type GameSCNScene, SKLabelNodes, and SpriteNodes. Here we create two LabelNodes: one for displaying score and the other to show "game over" text. We also create two spriteNodes: one for the play button and the other for the jump button.

We add the required init function and the default...