嗨,我遵循我的Xcode遊戲教程。當我運行模擬器時,它會成功啓動,但只要點擊下一頁就會崩潰。然後錯誤的 GameScene.swift彈出右鍵上述xcode sprite遊戲錯誤EXC_BAD_INSTRUCKION(code = EXC_1386,subcode = 0x0),啓動模擬器後
override func didMoveToView(view: SKView) {
/* Setup your scene here */
cannon = self.childNodeWithName("cannon") as! SKSpriteNode
是我有一個錯誤的部分。從
cannon = self.childNodeWithName("cannon") as! SKSpriteNode
和錯誤這樣表示
thread1:EXC_BAD_INSTRUCKION(code=EXC_1386, subcode=0x0)
這是我的代碼
進口SpriteKit
class GameScene: SKScene {
var cannon: SKSpriteNode!
var touchLocation:CGPoint = CGPointZero
**override func didMoveToView(view: SKView) {
/* Setup your scene here */
cannon = self.childNodeWithName("cannon") as! SKSpriteNode**
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
touchLocation = touches.first!.locationInNode(self)
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
touchLocation = touches.first!.locationInNode(self)
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
let percent = touchLocation.x/size.width
let newAngle = percent * 180 - 180
cannon.zRotation = CGFloat(newAngle) * CGFloat(M_PI); 180.0
請讓我知道什麼是錯在這裏。非常沮喪。謝謝
您是否嘗試將cannon = self.childNodeWithName(「cannon」)註釋掉! SKSpriteNode ** – helloGo