[英]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.