В настоящее время я изучаю Swift и особенно для Mac, и я пытался сделать что-то вроде битвы с покемонами. Для этого я хотел отобразить индикаторы прогресса для очков здоровья, но все, что я нашел, это полосатый. Я не знаю, могу ли я заставить их измениться в зависимости от заданного значения, или я не использую правильный тип IBOutlet.
Если кто-нибудь знает, как отображать индикаторы выполнения, это все, что мне нужно :)
Спасибо
(Я француз, так что извините за возможные ошибки...)
Изменить: вот часть моего кода
Переменные:
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet var window: NSWindow?
var firstPokemon:Pokemon = Pokemon(name: "Aquali", level: 50, HP: 245, power: 10)
//[...]
@IBOutlet var firstPokemonHealthBar: NSProgressIndicator!
//[...]
var firstPokemonOriginalHP:Float = 0
var secondPokemon:Pokemon = Pokemon(name: "Pikachu", level: 90, HP: 300, power: 13)
//[...]
@IBOutlet var secondPokemonHealthBar: NSProgressIndicator!
//[...]
var secondPokemonOriginalHP:Float = 0
инициализировать:
func applicationDidFinishLaunching(aNotification: NSNotification?)
{
firstPokemonOriginalHP = firstPokemon.HP
secondPokemonOriginalHP = secondPokemon.HP
}
update (вызывается после каждой атаки)
func update(str:String)
{
if firstPokemon.HP < 0 {firstPokemon.HP = 0}
if secondPokemon.HP < 0 {secondPokemon.HP = 0}
//firstPokemonName.stringValue = firstPokemon.name
//firstPokemonLevel.stringValue = "Level: " + String(Int(firstPokemon.level))
//firstPokemonHP.stringValue = "\(Int(firstPokemon.HP))/\(Int(firstPokemonOriginalHP))hp"
firstPokemonHealthBar.doubleValue = Double(firstPokemon.HP/firstPokemonOriginalHP)
//firstPokemonPicture.image = NSImage(named: "\(firstPokemon.name)")
//firstPokemonPicture.image.size = firstPokemonPicture.bounds.size
//secondPokemonName.stringValue = secondPokemon.name
//secondPokemonLevel.stringValue = "Level: \(Int(secondPokemon.level))"
//secondPokemonHP.stringValue = "\(Int(secondPokemon.HP))/\(Int(secondPokemonOriginalHP))hp"
secondPokemonHealthBar.doubleValue = Double(secondPokemon.HP/secondPokemonOriginalHP)
//secondPokemonPicture.image = NSImage(named: "\(secondPokemon.name)")
//secondPokemonPicture.image.size = secondPokemonPicture.bounds.size
//TextBoxInfos.stringValue = str
if firstPokemon.HP <= 0 || secondPokemon.HP <= 0
{
button1.enabled = false
button2.enabled = false
battleEnded()
}
}