April 2021
Beginner to intermediate
506 pages
11h 57m
English
In Create Your First Component, you created a health component to monitor an entity’s health. Later, in Build a Better Health Component, you enhanced this component by giving it the ability to run certain actions when an entity takes a hit or runs out of health. At the time, you weren’t ready to implement all of the actions for the player—now you are.
Switch to the HealthComponent.swift file, and in the didAddToEntity() method, replace the following code:
| | // TODO: Add code to restart the game |
| | // but for now, reset the player's health |
| | self.currentHealth = self.maxHealth |
with this code:
| | self.componentNode.scene?.loadGameOverScene() |
Excellent, this small change takes care of loading the game over ...
Read now
Unlock full access