我想增加in touch事件的高度,就像stick hero一样。我正在尝试以下代码
func changeHeight(){
let action = SKAction.resizeToHeight(self.leadherNode!.size.height+50, duration: 0.5);
let seq = SKAction.repeatActionForever(action)
self.leadherNode?.runAction(seq, withKey: "height")
}
但不幸的是它只是第一次增加了节点的高度并且它永远不会重复。我怎样才能做到这一点?
最佳答案
SKAction
启动后对其参数的更改不会影响操作。您将需要在每一步创建一个具有更新值的新操作。这是一种方法:
定义并初始化高度和最大高度属性
var spriteHeight:CGFloat = 50.0;
let maxHeight:CGFloat = 500.0
从 didMoveToView
调用它
resizeToHeight()
此函数创建一个 SKAction
将 sprite 的大小调整到特定高度。 Action 完成后,函数更新高度值,然后调用自身。
func resizeToHeight() {
self.leadherNode?.runAction(
SKAction.resizeToHeight(self.spriteHeight, duration: 0.5),
completion:{
// Run only after the previous action has completed
self.spriteHeight += 50.0
if (self.spriteHeight <= self.maxHeight) {
self.resizeToHeight()
}
}
)
}
关于ios - spritekit SKAction.resizeToHeight 不重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27580164/