为场景添加新动作是否会自动删除之前在 SpriteKit 中的动作?

Does adding new action for the scene remove automatically the one before in SpriteKit?

我想知道我是否做了序列动作,而这个序列是 运行 添加到场景的新动作,新动作是否会停止序列?

如果是,如果在 swift 中添加了新操作,我如何才能使它们都工作?

如果你试一试,我相信你会自己找到答案。

但无论如何,我已经为你试过了:

node.run(SKAction.sequence([SKAction.moveBy(x: 100, y: 0, duration: 3), SKAction.moveBy(x: 0, y: 100, duration: 3)]))
node.run(SKAction.rotate(byAngle: CGFloat(M_PI * 2), duration: 6))

我看到的是节点既移动又旋转。因此,您告诉节点 运行 的每个后续操作将同时 运行。

同时 运行 个动作的另一种方法是使用 SKAction.group.

我已经关注你的评论了,看来你是在动作重叠的情况下。

当你有一个节点并且你想启动一个或多个动作时,尤其是你的节点参与运动的序列动作,你应该确保这些动作完成了。

去做,比如对自己:

let seq = SKAction.sequence([action1,action2,..])
if self.action(forKey: "moveToRoof") == nil {
   self.run(seq, withKey:"moveToRoof")
}

您还可以这样做:

let group1 = SKAction.group([action1, action2,..])
let group2 = SKAction.group([action1, action2,..])
let addNewNode = SKAction.run{
    self.addChild(node)
}
let seq = SKAction.sequence([action1, group1, action2, addNewNode, group2,..])
if self.action(forKey: "moveToGround") == nil {
       self.run(seq, withKey:"moveToGround")
}

在您的情况下,您似乎想将节点添加到跟随其父位置的节点..

override func update(_ currentTime: TimeInterval) {
        if let child = myNode1, let parent = child.parent  { // if exist follow the parent position
            child.position = parent.position
        }
}

新操作唯一会干扰任何 运行ning 操作的情况是两个操作共享相同的密钥。如果您不分配键,那么每次您添加一个动作时,它都会被添加到动作池中并运行并发。