2017-01-10 2 views
1

私は、ゲームを作成しています私はこのエラーになっています。ここで私は信じているコードをここには_fatalerrorMessage(StaticString、StaticString、StaticString、UINT、フラグ:UInt32型)0_specialized - >を決してない - SpriteKitベース

0_specialized _fatalerrorMessage(StaticString, StaticString, StaticString, UInt, flags : UInt32) -> Never

をされますクラッシュがである:

func goToCongratsScene() { 

    if countTouches > 5 { 
    let gameScene:GameScene = GameScene(size: self.size) 
    let transition = SKTransition.reveal(with: SKTransitionDirection.down, duration: 0) 
    gameScene.scaleMode = SKSceneScaleMode.aspectFill 
    self.view!.presentScene(gameScene, transition: transition) 
    } 
} 

The Game Scene

import UIKit 
import SpriteKit 

class GameScene: SKScene { 
    override func didMove(to view: SKView) { 

    backgroundColor = UIColor(red: CGFloat(248), green: CGFloat(248), blue: CGFloat(248), alpha: CGFloat(255)) //SKColor 

    var message = "Good Job! " 
    let label = SKLabelNode(fontNamed: "AppleSDGothicNeo-Bold") 
    label.text = message 
    label.fontSize = 22 
    label.fontColor = SKColor.blue 
    self.backgroundColor = SKColor.black 
    label.position = CGPoint(x: size.width/2, y: size.height/2) 
    addChild(label) 

    run(SKAction.sequence([ 

     SKAction.wait(forDuration: 1.0), 
     SKAction.run(){ 

     var scene = GameOver(size: self.size) 
     let skView = self.view! as SKView 
     skView.ignoresSiblingOrder = true 
     scene.scaleMode = .resizeFill 
     scene.size = skView.bounds.size 
     skView.presentScene(scene) 
    } 
    ])) 
    } 
} 
+1

コードにいくつかのブレークポイントを追加して、アプリケーションがクラッシュしているコードブロックを検出します。たとえば、 "didMove"が呼び出されたか、またはブレークポイントを追加すると、 – Stefan

+0

の前にクラッシュが発生し、そのセクションのブレークポイントであるとゲームを開始します。 – Robert

+0

アプリケーションをクラッシュさせるまでブレークポイントを追加します。次にclikc "次のブレークポイントに移動"し、クラッシュすると問題のある行がわかります。 – Fluidity

答えて

0

私は質問にあなたの問題を再現困難な時期を持っていたので、私はちょうどfoはそれを書き直しあなた。ここではシンプルなゲームです...メイン画面で6回タップして勝利します...それから自動的にあなたは1.5秒(あなたの遅れ)の後に負けになります

メイン画面でタップの代わりにドラッグすると、すぐに失われます。

私は必要ならば何でも喜んで説明することができます。それがお役に立てば幸い:

import SpriteKit 

// Give us some functions that we can use in all of our scenes (inheritance): 
extension SKScene { 

// We don't need to use `self` anywhere for now, 
// because `size` and `view` are are already members of `SKScene`. 

    func goToGameOverScene() { 
    let scene  = GameOver(size: size) 
    scene.scaleMode = .resizeFill 

    view!.ignoresSiblingOrder = true 
    view!.presentScene(scene) 
    } 

    func goToCongratsScene() { 
    let congratsScene = Congrats(size: size) 
    let transition = SKTransition.reveal(with: SKTransitionDirection.down, 
              duration: 0) 
    congratsScene.scaleMode = .aspectFill 
    view!.presentScene(congratsScene, transition: transition) 
    } 

    func goToGameScene() { 
    let gameScene  = GameScene(size: size) 
    gameScene.scaleMode = .aspectFill 
    view!.presentScene(gameScene) 
    } 

    func makeLabel(text: String) { 
    let label  = SKLabelNode(fontNamed: "AppleSDGothicNeo-Bold") 
    label.text  = text 
    label.fontSize = 22 
    label.fontColor = SKColor.blue 
    label.position = CGPoint(x: size.width/2, y: size.height/2) 
    addChild(label) 
    } 
} 

class GameOver: SKScene { 

    override func didMove(to view: SKView) { 
    makeLabel(text: "Game Over!! Muahahaha!") 
    } 

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 
    goToGameScene() 
    } 
} 

class Congrats: SKScene { 

    override func didMove(to view: SKView) { 

    backgroundColor = SKColor(red: CGFloat(248), 
           green: CGFloat(248), 
           blue: CGFloat(248), 
           alpha: CGFloat(255)) 

    backgroundColor = SKColor.black // Not sure which color you wanted :) 

    makeLabel(text: "you won... or did you?") 

    run(.sequence([ 
     .wait(forDuration: 1.5), 
     .run() { self.goToGameOverScene() } // We have to use `self` here because in closure. 
    ])) 

    } 
} 

class GameScene: SKScene { 

    var countTouches = 0 

    override func didMove(to view: SKView) { 
    makeLabel(text: "Tap six times to 'win'~!") 
    } 

    // Six taps to win! 
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 
    countTouches += 1 
    if countTouches > 5 { goToCongratsScene() } 
    } 

    // Game over if you move your finger! 
    override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { 
    goToGameOverScene() 
    } 
} 

私はあなたの問題は... didMoveToViewとクロージャの内側の周りにシーンを交換しようとselfはそのように迅速混乱得ることができます使用してから来たと思います。

ここでは、すべてのものを並べて、それに独自の関数を与えました。そこで、私はちょっと簡単にどこに移動するのかわかります。

関連する問題