[英]spritekit SKAction.resizeToHeight is not repeating
I want to increase the height of in touch events, it's same like stick hero is doing.我想增加触摸事件的高度,就像棒英雄所做的一样。 I am trying following code
我正在尝试以下代码
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")
}
but unfortunately it just increase the height of node for first time and it never repeats.但不幸的是,它只是第一次增加节点的高度,它永远不会重复。 How can I achieve this?
我怎样才能做到这一点?
I dont know swift.我不知道迅速。 But I can write objective-c version.
但是我可以写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]];
Changes to an argument of an SKAction
after it has started will have no effect on the action. SKAction
启动后对其参数的更改不会影响该操作。 You will need to create a new action with the updated value at each step.您需要在每一步创建一个具有更新值的新操作。 Here's one way to do that:
这是一种方法:
Define and initialize the height and max height properties定义和初始化高度和最大高度属性
var spriteHeight:CGFloat = 50.0;
let maxHeight:CGFloat = 500.0
Call this from didMoveToView
从
didMoveToView
调用这个
resizeToHeight()
This function creates an SKAction
that resizes a sprite to a specific height.此函数创建一个
SKAction
,将精灵大小调整为特定高度。 After the completion of the action, the function updates the height value and then calls itself.动作完成后,函数更新高度值,然后调用自身。
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.