April 2021
Beginner to intermediate
506 pages
11h 57m
English
Switch to the GeneratorComponent.swift, and at the bottom of the spawnMonsterEntity() method, after the line that reads monsterEntity.addComponent(physicsComponent), add the following code:
| | if let scene = componentNode.scene as? GameScene { |
| | scene.entities.append(monsterEntity) |
| | } |
This code adds the “spawned” monster entity to the scene’s entities array, which you need to do so that the attached components participate in the update routine. This update takes place in the GameScene’s update(_:) method, which looks like this:
| | // Update entities |
| | for entity in self.entities { |
| | entity.update(deltaTime: dt) |
| | } |
Fantastic, you’re ready to test the new monster agent goals. ...
Read now
Unlock full access