[英]spritekit SKAction.resizeToHeight is not repeating
我想增加触摸事件的高度,就像棒英雄所做的一样。 我正在尝试以下代码
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")
}
但不幸的是,它只是第一次增加节点的高度,它永远不会重复。 我怎样才能做到这一点?
我不知道迅速。 但是我可以写objective-c版本。
CGFloat currentSpriteSize;//Create private float
SKSpriteNode *sprite;//Create private sprite
currentSpriteSize = sprite.size.height;//Into your start method
//And your Action
SKAction *seq = [SKAction sequence:@[[SKAction runBlock:^{
currentSpriteSize += 50;
}], [SKAction resizeToHeight:currentSpriteSize duration:0.5]]];
[sprite runAction:[SKAction repeatActionForever:seq]];
SKAction
启动后对其参数的更改不会影响该操作。 您需要在每一步创建一个具有更新值的新操作。 这是一种方法:
定义和初始化高度和最大高度属性
var spriteHeight:CGFloat = 50.0;
let maxHeight:CGFloat = 500.0
从didMoveToView
调用这个
resizeToHeight()
此函数创建一个SKAction
,将精灵大小调整为特定高度。 动作完成后,函数更新高度值,然后调用自身。
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()
}
}
)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.