[英]Updating parameter of an SKAction that is repeating forever swift
我现在有一个功能,可以在我正在设计的游戏中对球进行动画处理。 但是,我希望动画速度随球的实际速度而变化,这是我已经实现的,但仅在每次动画迭代后才达到。 这使它显得有些断断续续,我正在寻找一种更优雅的解决方案,可以更新timePerFrame参数中间动作。 我最初将其设置为永远重复,但是意识到一旦动作开始,timePerFrame不会更新。 有没有办法使此动画速度更改更平稳?
func animBall() {
//This is the general runAction method to make our ball change color
var animSpeedNow = self.updateAnimSpeed()
println(animSpeedNow)
var animBallAction = SKAction.animateWithTextures(ballColorFrames, timePerFrame: animSpeedNow,resize: false, restore: true)
self.runAction(animBallAction, completion: {() -> Void in
self.animBall()
})
}
func updateAnimSpeed() -> NSTimeInterval{
// Update the animation speed based on the velocity to syncrhonize animation with ball velocity
var velocX = self.physicsBody!.velocity.dx
var velocY = self.physicsBody!.velocity.dy
if abs(velocX) > 0 || abs(velocY) > 0 {
var veloc = sqrt(velocX*velocX + velocY*velocY)
var animSpeedNow: NSTimeInterval = NSTimeInterval(35/veloc)
let minAS = NSTimeInterval(0.017)
let maxAS = NSTimeInterval(0.190)
if animSpeedNow < minAS {
return maxAS
}
else if animSpeedNow > maxAS {
return minAS
}
else {
return animSpeedNow
}
}
else {
return NSTimeInterval(0.15)
}
}
如果无法直接操纵永远运行的SKAction的参数,我想我
在您的情况下,一种更简单的方法是删除旧的动画动作并将其替换为新的动画动作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.