So I started making a game and I wanted to use a progress bar as a health bar for many different things and I couldn't figure out why it wasn't updating at all. It did, however, update in the viewdidload function. Here is the code that I am using.
func updateHealthBars() {
hullHealthBar.setProgress(hullHealth/hullHealthMax, animated: true)
cannonsHealthBar.setProgress(cannonsHealth/cannonsHealthMax, animated: true)
sailsHealthBar.setProgress(sailsHealth/sailsHealthMax, animated: true)
crewHealthBar.setProgress(crewHealth/crewHealthMax, animated: true)
}
@IBAction func setSailButton(sender: AnyObject) {
if hullHealth > 0 {
hullHealth-=20
}
else if cannonsHealth > 0 {
cannonsHealth-=20
}
else if sailsHealth > 0 {
sailsHealth-=20
}
else if crewHealth > 0 {
crewHealth-=20
}
updateHealthBars()
}
If anybody knows what I need to do to update their health when I press the button, I would be very thankful because I have been trying to do this for a while now without success. I am using XCode 6.