我是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()
})
}