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