【发布时间】:2017-07-30 20:49:20
【问题描述】:
我正在尝试通过采用 1 个输入参数的 SKAction 调用函数。
当我声明 SKAction 时,我收到一个错误:“无法将类型 '()' 的值转换为预期的参数类型 '() -> Void'
self.run(SKAction.repeat(SKAction.sequence([SKAction.wait(forDuration: 1), SKAction.run(self.decreaseHealth(by: 5.0))]), count: 10))
func decreaseHealth(by amount: Double){
print(health)
health -= amount
print(health)
let percentageToDecrease = amount / totalHealth
let resizeAction = SKAction.resize(toHeight: CGFloat(600*(1-percentageToDecrease)), duration: 1)
let redAmount: CGFloat = CGFloat(1.0 - health / totalHealth)
let greenAmount: CGFloat = CGFloat(health / totalHealth)
let recolorAction = SKAction.colorize(with: UIColor(red: redAmount, green: greenAmount, blue: CGFloat(0.0), alpha: CGFloat(1.0)), colorBlendFactor: 0, duration: 1)
healthBar.run(SKAction.group([resizeAction, recolorAction]))
}
【问题讨论】:
-
为什么你甚至需要使用 SKAction 来运行你的函数?
-
我需要使用一个动作来运行该函数,因为我将在一系列动作中使用它,重复多次。我不能简单地调用函数。
-
你没有完全解释你的情况。动作顺序是怎样的?你打算重复这个序列多少次?
-
@ElTomato 我已经编辑了包含的代码,以更好地说明为什么我想用 SKAction 调用这个函数。
标签: swift sprite-kit skaction