O'Reilly logo

Learning iOS 8 Game Development Using Swift by Siddharth Shekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required