Cannot use unarchiveFromFile to set GameScene in SpriteKit

走远了吗. 提交于 2019-12-02 13:19:36

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!