gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 06:27:01 25 4
gpt4 key购买 nike

我正在创建一个游戏,但出现此错误:

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.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 会像那样很快变得困惑。

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

关于ios - 0_specialized _fatalerrorMessage (StaticString, StaticString, StaticString, UInt, flags : UInt32) -> Never - SpriteKit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41575674/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com