April 2021
Beginner to intermediate
506 pages
11h 57m
English
Switch to the GameScene.swift file and look at the didMove(To:) method. Notice there’s a lot of player-related code stuffed into this method. Let’s tidy up this method by moving the player-related code into its own set-up method.
Below the setupCamera() method, add the following code:
| | func setupPlayer() { |
| | player = childNode(withName: "player") as? Player |
| | |
| | if let player = player { |
| | player.move(.stop) |
| | agentComponentSystem.addComponent(player.agent) |
| | } |
| | } |
Essentially, this is the same code that’s currently in the didMove(to:) method with one exception: you’re adding the player.agent component to the agent component system so that it participates in the update routine.
Read now
Unlock full access