April 2021
Beginner to intermediate
506 pages
11h 57m
English
At the moment, the player node moves to the tap location instead of staying on the platform. There’s a way to fix this problem using constraints and the SKConstraint class.
With constraints, you can restrict a node’s movement to a specific area. In this case, you need to limit the player.position.y value to keep Blob firmly on the platform.
Open the Player.swift file and add a new method above the walk() method:
| | func setupConstraints(floor: CGFloat) { |
| | let range = SKRange(lowerLimit: floor, upperLimit: floor) |
| | let lockToPlatform = SKConstraint.positionY(range) |
| | |
| | constraints = [ lockToPlatform ] |
| | } |
This new method sets up a range with an upper and lower limit using the values you pass in ...
Read now
Unlock full access