Skip to content

Instantly share code, notes, and snippets.

@EricGustin
Last active April 22, 2022 08:41
Show Gist options
  • Select an option

  • Save EricGustin/fefcc8583d719a9e282b02b8865badfb to your computer and use it in GitHub Desktop.

Select an option

Save EricGustin/fefcc8583d719a9e282b02b8865badfb to your computer and use it in GitHub Desktop.
@objc func hitEnemy() {
updateHealthBar()
UIView.animate(withDuration: 0.25, animations: {
self.enemy.transform = CGAffineTransform(scaleX: 0.8, y: 0.8) // Scale the enemy down to 0.8 of its size over 1/4 of a second
}) { _ in
UIView.animate(withDuration: 0.25) {
self.enemy.transform = .identity // Once the enemy is done scaling down in size, have it return to its original size over a period of 1/4 of a second
}
}
}
private func updateHealthBar() {
UIView.animate(withDuration: 0.5) {
self.healthBar.setProgress(self.healthBar.progress - 0.25, animated: true) // Take away a fourth of the enemy's health over a period of 1/2 of a second
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment