首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >0_specialized _fatalerrorMessage(StaticString,UInt,旗子: UInt32) -> UInt SpriteKit

0_specialized _fatalerrorMessage(StaticString,UInt,旗子: UInt32) -> UInt SpriteKit
EN

Stack Overflow用户
提问于 2017-01-10 18:18:19
回答 1查看 460关注 0票数 1

我正在创建一个游戏,在这个游戏中我得到了这个错误:

0_specialized _fatalerrorMessage(StaticString,UInt,旗子: UInt32) ->从不

以下是我认为坠机的代码所在:

代码语言:javascript
复制
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)
  }
}

游戏场景

代码语言:javascript
复制
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)
     }
    ]))
  }
}
EN

回答 1

Stack Overflow用户

发布于 2017-01-11 20:30:17

我在这个问题上很难重现你的问题,所以我给你重写了一遍。这是一个简单的游戏..。你敲了六下主屏幕才能赢..。然后它会自动让你在1.5秒后输掉(你的延迟)

在游戏的屏幕上,你点击重置。

如果在主屏幕上拖动而不是点击,则会立即丢失。

如果你需要的话,我可以很高兴地解释任何事情。希望它有帮助:

代码语言:javascript
复制
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会像那样迅速地使人感到困惑。

在这里,我只是把所有的东西分开,赋予它自己的功能,这样你就可以跟着移动到我认为更容易的地方。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41575674

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档