Cannot use unarchiveFromFile to set GameScene in SpriteKit

后端 未结 1 1833
耶瑟儿~
耶瑟儿~ 2021-01-27 09:03

I\'m using Xcode 7 beta 2 and following raywenderlich.com\'s Breakout tutorial to learn SpriteKit. Here\'s the error I get when I try to load GameScene using unarchiveFromFile.<

相关标签:
1条回答
  • 2021-01-27 09:44

    You should use the init(fileNamed:) initialiser, which is available from iOS 8 onwards. For example:

    if let gameOverScene = GameOverScene(fileNamed: "GameOverScene") {
        // ...
    }
    

    It's important to note that init(fileNamed:) is a convenience initialiser on SKNode:

    convenience init?(fileNamed filename: String)
    

    Therefore, for GameOverScene to automatically inherit init(fileNamed:), GameOverScene must adhere to the following rules from The Swift Programming Language: Initialisation (rule 2 especially):

    Assuming that you provide default values for any new properties you introduce in a subclass, the following two rules apply:

    Rule 1 If your subclass doesn’t define any designated initializers, it automatically inherits all of its superclass designated initializers.

    Rule 2 If your subclass provides an implementation of all of its superclass designated initializers—either by inheriting them as per rule 1, or by providing a custom implementation as part of its definition—then it automatically inherits all of the superclass convenience initializers.

    0 讨论(0)
提交回复
热议问题