如何解决这个问题我已经看过其他答案,但无法弄清楚我的问题。
由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [Tap_Car.GameOver setNormalTexture:]:无法识别的选择器发送到实例0x10123acf0' ***第一次抛出调用堆栈: (0x184406fd8 0x182e68538 0x18440def4 0x18440af4c 0x184306d2c 0x193b60228 0x184e56420 0x184e5cf00 0x184df283c 0x184e56420 0x184e55b58 0x193b4f8ac 0x193b65738 0x193b15bb8 0x10009ec84 0x10009ed24 0x193b4f3c8 0x193b65738 0x193b15bb8 0x184e56420 0x184e55b58 0x193b4ed50 0x100099a0c 0x100099848 0x100094064 0x10009416c 0x18a403f14 0x18a401f84 0x193b18cf8 0x193b386dc 0x193b35188 0x193b3465c 0x193b3628c 0x193b6b7b4 0x100f344fc 0x187616600 0x1876164b0 0x184673dd4 0x18439d958 0x1843b5adc 0x1843b527c 0x1843b2d90 0x1842e2d94 0x185d4c074 0x18a59b130 0x10009f9ec 0x1832f159c) libc ++ abi.dylib:以NSException类型的未捕获异常终止 (lldb)
当此代码运行时会发生这种情况
let gameover = SKScene(fileNamed: "GameOverScene")!
gameover.scaleMode = .aspectFill
view?.presentScene(gameover, transition: SKTransition.crossFade(withDuration: 1.4))
这是“GameOverScene”的代码
import Foundation
import SpriteKit
class GameOver: SKScene{
var restart = SKLabelNode()
var highscorelbl = SKLabelNode()
var homescreen = SKLabelNode()
var scorelbl = SKLabelNode()
override func didMove(to view: SKView) {
self.anchorPoint = CGPoint(x: 0.5, y: 0.5)
restart = self.childNode(withName: "restart") as! SKLabelNode
highscorelbl = self.childNode(withName: "highscore") as! SKLabelNode
homescreen = self.childNode(withName: "homescreen") as! SKLabelNode
scorelbl = self.childNode(withName: "score") as! SKLabelNode
if highscoredefault.value(forKey: "highscore") != nil{
highscore = highscoredefault.integer(forKey: "highscore")
highscorelbl.text = "High Score: \(highscore)"}
scorelbl.text = "Score: \(score)"
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches{
let touchlocation = touch.location(in: self)
if atPoint(touchlocation).name == "restart"{
let gamescene = SKScene(fileNamed: "GameScene")!
gamescene.scaleMode = .aspectFill
view?.presentScene(gamescene, transition: SKTransition.crossFade(withDuration: (0.8)))
}
if atPoint(touchlocation).name == "homescreen"{
let gamemenu = SKScene(fileNamed: "GameMenu")!
gamemenu.scaleMode = .aspectFill
view?.presentScene(gamemenu, transition: SKTransition.crossFade(withDuration: (0.8)))
}
}
}
}