如何等待动作结束以在 SpriteKit 中执行函数?

How do I wait for the end of an action to execute a function in SpriteKit?

我创建了一个移动节点位置的动作。

我想在动作结束后换场景

我能做什么?

我尝试放置一个 while position != targetPosition,但这会阻止操作。

func moveBattleScene(node: SKNode) {
    let width = frame.size.width
    let rectSize = width / 4
    let moveLeft = SKAction.moveBy(x: -rectSize * 2, y: 0, duration: 1)
    node.run(moveLeft)
 }

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    for touch in touches {
        let location = touch.location(in: self)
        let nodeB = self.childNode(withName: "BATTLEBUTTON")
        let frameB = nodeB!.calculateAccumulatedFrame()
        let minX = frameB.minX
        let maxX = frameB.maxX
        let minY = frameB.minY
        let maxY = frameB.maxY
        if location.x > minX && location.x < maxX {
            if location.y > minY && location.y < maxY {
                changeLabel(labelNode: nodeB?.childNode(withName: "B") as! SKLabelNode)
                moveBattleScene(node: self.childNode(withName: "BATTLEBUTTON")!)
                self.childNode(withName: "BATTLEBUTTON")!.action
                let width = frame.size.width
                let rectSize = width / 4
                let finalPos = CGPoint(x: -rectSize * 2, y: 0)
                if self.childNode(withName: "BATTLEBUTTON")!.position == finalPos {
                    let gameScene = GameScene(size: view!.bounds.size)
                    view!.presentScene(gameScene)
                }
            }
        }
    }
}

已解决!!!

func changeScene() {
    let gameScene = GameScene(size: view!.bounds.size)
    view!.presentScene(gameScene)
}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    for touch in touches {
        let location = touch.location(in: self)
        let nodeB = self.childNode(withName: "BATTLEBUTTON")
        let frameB = nodeB!.calculateAccumulatedFrame()
        let minX = frameB.minX
        let maxX = frameB.maxX
        let minY = frameB.minY
        let maxY = frameB.maxY
        if location.x > minX && location.x < maxX {
            if location.y > minY && location.y < maxY {
                changeLabel(labelNode: nodeB?.childNode(withName: "B") as! SKLabelNode)
                let width = frame.size.width
                let rectSize = width / 4
                let moveLeft = SKAction.moveBy(x: -rectSize * 2, y: 0, duration: 1)
                nodeB!.run(moveLeft, completion: {self.changeScene()})
            }
        }
    }
}