Ios 0 \u专用\u fatalerrorMessage(StaticString、StaticString、StaticString、UInt、标志:UInt32)->;永不-斯皮特基特

Ios 0 \u专用\u fatalerrorMessage(StaticString、StaticString、StaticString、UInt、标志:UInt32)->;永不-斯皮特基特,ios,swift,sprite-kit,Ios,Swift,Sprite Kit,我正在创建一个游戏,在那里我会遇到以下错误: 0\u专用\u fatalerrorMessage(StaticString、StaticString、StaticString、UInt、标志:UInt32)->Never 以下是我认为坠机原因的代码: func goToCongratsScene() { if countTouches > 5 { let gameScene:GameScene = GameScene(size: self.size) let

我正在创建一个游戏,在那里我会遇到以下错误:

0\u专用\u fatalerrorMessage(StaticString、StaticString、StaticString、UInt、标志: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)
  }
}
游戏场景


我很难在问题中重现你的问题,所以我只是为你重写了它。这里有一个简单的游戏。。。您在主屏幕上轻触六次以赢得。。。然后,它会在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()
  }
}
导入SpriteKit
//给我们一些可以在所有场景中使用的函数(继承):
扩展SKScene{
//我们现在不需要在任何地方使用self,
//因为'size'和'view'已经是'SKScene'的成员。
func goToGameOverScene(){
让场景=游戏结束(大小:大小)
scene.scaleMode=.resizeFill
查看!.ignoresSiblingOrder=true
查看!.presentScene(场景)
}
func Gotocongratscene(){
让我们祝贺你=祝贺(大小:大小)
let transition=SKTransition.discover(带:SKTransitionDirection.down,
持续时间:0)
恭喜你.scaleMode=.aspectFill
view!.presentScene(恭喜,过渡:过渡)
}
func goToGameScene(){
让游戏场景=游戏场景(大小:大小)
gameScene.scaleMode=.aspectFill
查看!.presentScene(游戏场景)
}
func makeLabel(文本:字符串){
let label=SKLabelNode(fontname:“appledgothicneo Bold”)
label.text=文本
label.fontSize=22
label.fontColor=SKColor.blue
label.position=CGPoint(x:size.width/2,y:size.height/2)
addChild(标签)
}
}
类游戏结束:SKScene{
覆盖func didMove(到视图:SKView){
makeLabel(文字:“游戏结束!!哈哈哈!”)
}
覆盖func TouchesBegind(Touchs:Set,带有事件:UIEvent?){
goToGameScene()
}
}
全班祝贺:SKScene{
覆盖func didMove(到视图:SKView){
背景色=SKColor(红色:CGFloat(248),
绿色:CGFloat(248),
蓝色:CGFloat(248),
阿尔法:CGFloat(255))
backgroundColor=SKColor.black//不确定要哪种颜色:)
makeLabel(文本:“你赢了……还是你赢了?”)
按顺序运行([
.等待(持续时间:1.5),
.run(){self.goToGameOverScene()}//我们必须在这里使用'self',因为在闭包中。
]))
}
}
类游戏场景:SKScene{
var=0
覆盖func didMove(到视图:SKView){
makeLabel(文本:“点击六次以“赢”~!”)
}
//六次轻击获胜!
覆盖func TouchesBegind(Touchs:Set,带有事件:UIEvent?){
计数+=1
如果countTouchs>5{gotocongratscene()}
}
//如果你动一下手指,游戏就结束了!
覆盖功能触摸移动(touchs:Set,带有事件:UIEvent?){
goToGameOverScene()
}
}
我认为您的问题来自于尝试交换
didMoveToView
和闭包内部的场景。。。而使用
self
会很快变得混乱


在这里,我只是将所有内容隔开,赋予它自己的功能,这样你就可以更容易地跟踪哪里移动到哪里。

在代码中添加一些断点,以检测应用程序崩溃的代码块。例如,调用“didMove”或崩溃发生在我添加断点之前,并且开始玩游戏时,在该部分中会显示他们的断点添加断点,直到到达导致应用程序崩溃的那一行。然后你点击“转到下一个断点”,当它崩溃时,你知道问题在哪一行。
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()
  }
}