SKAction 等待间隔不一致

SKAction wait interval NOT consistent

我有一个函数可以创建 SpriteNode 副本并以指定的间隔沿矩形路径移动每个副本。我对这个间隔有一个问题,即动作以不一致的间隔执行,在动作为 运行.

时在 sprite 节点之间产生奇怪的间隙
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:),这是预期的行为。文档指出:

Creates an action that idles for a randomized period of time.

我认为您正在寻找 wait(forDuration:) 方法,它会工作得很好:)