April 2021
Beginner to intermediate
506 pages
11h 57m
English
In the Project Navigator, select the HealthComponent.swift file and add two new properties:
| | private var hitAction = SKAction() |
| | private var dieAction = SKAction() |
You’ll use these properties to preload the actions needed to handle hits and “deaths” for both the monsters and the player. While you can preload these actions in other ways, you’ll opt for simplicity over versatility.
In the didAddToEntity() method, add the following code below the line that reads updateHealth(0, forNode: componentNode):
| | if let _ = componentNode as? Player { |
| | hitAction = SKAction.playSoundFileNamed("player_hit", |
| | waitForCompletion: false) |
| | |
| | let playSound = SKAction.playSoundFileNamed("player_die" ... |
Read now
Unlock full access