Adding wall and floor parallax
What is a game without a parallax effect? In SpriteKit
, we added parallax using sprites. In SceneKit
, we will use planes to add it to the scene. Apart from adding parallax, we will also see how to add diffuse, normal, and specular maps to the plane. Also, we will learn what those terms mean.
Create a new file called ScrollingBackground.swift
.
Add four global SCNNodes
:
import SceneKit class ScrollingBackground{ var parallaxWallNode1: SCNNode! var parallaxWallNode2: SCNNode! var parallaxFloorNode1: SCNNode! var parallaxFloorNode2: SCNNode!
Add a new function, called create, and pass in a variable called currentScene
as GameSCNScene
. Add the following code to the create function:
func create(currentScene: GameSCNScene){ ...
Get Swift Game Development - Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.