如何创建重置功能?

时间:2018-12-04 05:51:16

标签: swift sprite-kit reset

我是spritekit的新手,我真的不知道自己在做什么。我只需要知道如何对复位功能进行编码,就可以在输赢后重新开始游戏。这就是我到目前为止所拥有的。

override func didMove(to view: SKView) {
    if createdContent == false {
        print("didMove")
        createCorgiNode()
        createBackground()
        createGround()
        createCamera()
        createGoalNode()
        createTreatNode(atXCoordinate: 200)
        createTreatNode(atXCoordinate: 600)
        createTreatNode(atXCoordinate: 1000)
        createTreatNode(atXCoordinate: 1500)
        createTreatNode(atXCoordinate: 2000)
        createTreatNode(atXCoordinate: 2500)
        createTreatNode(atXCoordinate: 3100)
        createTreatNode(atXCoordinate: 4000)

        var x = 800.0
        for _ in 1...5 {
            createEnemyNode(x: x)
            x = x + 1000.0 + Double.random(in: 0...1000)
        }
        createScoreLabel()
        createSound()
        physicsWorld.contactDelegate = self
        createdContent = true
    }
    else {
        resetGame()
    }
    view.showsFPS = true
    view.showsNodeCount = true
    view.showsDrawCount = true
    view.showsQuadCount = true
}


func resetGame() {
    score = 0
    enumerateChildNodes(withName: "TreatNode", using: {(node, _) in 
        node.removeFromParent()
    })
}

0 个答案:

没有答案