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

Implementing the parallax effect


To create a parallax effect for the background, we have to create a new class similar to how we created the MovingSprite class. So, go to File | New | File and create a new swift file called ParallaxSprite.

In the file, import SpriteKit at the top of the file and create some constants. In the class, we will just take the name of the file that we want for the parallax effect. Then we will create two sprites called sprite1 and sprite2 from it. We will take a value of speed at which we want to move the sprites. We will then take the instance of the GameplayScene class so that we can add the sprites to the gameplay class. We will also create a global constant to get the size of the view:

import Foundation
import SpriteKit

class ParallaxSprite{
    
    let _sprite1: SKSpriteNode!
    let _sprite2: SKSpriteNode!
    let _speed : CGFloat = 0.0
    let _viewSize:CGSize!
    
} //class end

Next, we will create the init function for the class in which we will take the...