April 2021
Beginner to intermediate
506 pages
11h 57m
English
Currently, the player object is defined in the scene using a local variable within a single method. This approach won’t work because you need access to the player object from outside of that single method. To fix this problem, you’ll add a new player property to the GameScene and remove the local player variable from the didMove(to:) method.
Still inside the GameScene.swift file, add the following property to the GameScene class, just above the didMove(to:) method:
| | let player = Player() |
Then, change the player set-up code in the didMove(to:) method to match this:
| | // Set up player |
| | player.position = CGPoint(x: size.width/2, y: foreground.frame.maxY) |
| | addChild(player) |
| | player.walk() |
This code gives you ...
Read now
Unlock full access