![](/img/trans.png)
[英]Wait after [SKAction playSoundFileNamed:waitForCompletion:]
[英]SKAction wait interval NOT consistent
我有一個函數創建SpriteNode副本並以指定的間隔沿矩形路徑移動每個副本。 我對此間隔有一個問題,即操作以不一致的間隔執行,在操作運行時在精靈節點之間產生奇怪的間隙。
var items = [SKSpriteNode]();
let item = SKSpriteNode(imageNamed: "Spaceship");
func createItem(scene: SKScene) {
let square = UIBezierPath(rect: CGRect(x: -300, y: -150, width: 700, height: 300));
let follow = SKAction.follow(square.cgPath, asOffset: false, orientToPath: false, duration: 5.0);
for i in 0..<6 {
if let itemCopy = item.copy() as? SKSpriteNode {
itemCopy.position = CGPoint(x: -300, y: -150);
items.append(itemCopy);
scene.addChild(itemCopy);
let otherWait = SKAction.wait(forDuration: 1.0, withRange: 2.0);
let otherSequence = SKAction.sequence([otherWait, SKAction.repeatForever(follow)]);
itemCopy.run(otherSequence);
}
}
}
我的理解是我不能依賴for loop
來定時,這個問題可能是由此造成的。 有沒有辦法通過某種回調函數解決這個問題?
這里的問題與for循環無關,但是來自你正在使用wait(forDuration:withRange:)
事實,這是預期的行為。 文件說明:
創建一個隨機時間段空閑的動作。
我想你正在尋找wait(forDuration:)
方法,它會工作得很好:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.