【问题标题】:Getting an error in SpriteKit. - Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1007351fc)在 SpriteKit 中出现错误。 - 线程 1:EXC_BREAKPOINT(代码=1,子代码=0x1007351fc)
【发布时间】:2017-01-05 06:43:03
【问题描述】:

我正在创建一个游戏,我正在寻找某人来编辑我的代码,说明为什么会出现此错误代码:

线程 1:EXC_BREAKPOINT(代码=1,子代码=0x1007351fc)

这是我的代码:

import UIKit

import SpriteKit

class Winner: SKScene {

override init(size: CGSize) {
    super.init(size: size)

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

    var message = "Great 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() {

            let reveal = SKTransition.flipHorizontal(withDuration: 1.0)
            let scene = GameOver(size: self.size)

            self.view?.presentScene(scene, transition:reveal)


        }
        ]))


}

required init?(coder aDecoder: NSCoder) {
   fatalError("init(coder:) has not been implemented")

}
 }

【问题讨论】:

    标签: ios swift sprite-kit


    【解决方案1】:

    您的问题只有几行,但我认为您的代码中应该有 2 个错误。

    第一个问题(谁造成了EXC_BREAKPOINT)可能是您将第一行写在:

    override init(size: CGSize) {
            super.init(size: size)
            // here there is your code
    }
    

    这将解释该方法的存在: required init?(coder aDecoder: NSCoder) {} 在你的场景类中, 但是当前场景可以使用便捷的构造函数进行初始化:

    public convenience init?(fileNamed filename: String)
    

    您在其中调用 SKS 相关文件场景。换句话说,在您的GameViewController 中您应该这样做:

    if let scene = SKScene(fileNamed: "GameScene") {}
    

    代替:

    let scene = SKScene(size: self.view.frame.size)
    

    所以编译器崩溃到:

    required init?(coder aDecoder: NSCoder) {
            fatalError("init(coder:) has not been implemented")
    }
    

    因为您的类会覆盖(然后调用)经典的 init 方法。

    第二个问题是当SKScene 对象已经由SKView 对象提供时,必须调用SKTransition,因此您可以在以下位置使用您的代码:

    override func didMove(to view: SKView) {
            print("GameScene")
            // here there is your code
    }
    

    确实,在视图呈现场景后立即调用此方法。

    【讨论】:

    • 感谢您的帮助。你能检查一下我更新的问题,它在转换到场景时从哪里得到我的错误。
    • 这可能取决于你如何创建你的 Congratulations 类,我不知道它的代码..
    • 我再次更新了我的代码。你可以看到我的祝贺课。
    • 在您的 Congratulation 课程中,您从 init 方法过渡到另一个场景:看看我对第二个问题的回答..
    • 那么,我应该在我的 Congratulation 类中添加 didMove 函数并打印出下一个场景吗?
    猜你喜欢
    • 1970-01-01
    • 2012-11-11
    • 1970-01-01
    • 1970-01-01
    • 2015-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多