试图从我的GameScene.swift类调用genericnode类中的endGame()
函数。当我尝试通过调用GameScene().endGame()
来访问它时,我收到错误:
无法为没有参数的“GameScene”类型调用初始值设定项
GameScene:
class GameScene: SKScene, SKPhysicsContactDelegate {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(size: CGSize){
super.init(size: size)
}
func endGame() {
gameOver = true
scoreboardSetup()
}
}
carNode.swift
enum CarType:Int {
case normalCar = 0
}
class carNode: GenericNode {
var carType:carType!
override func collisionWithPlayer(player: SKNode) -> Bool {
GameScene().endGame() //Gives me an error
return false
}
}