Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iOS SpriteKit模板中重命名默认场景?_Ios_Swift_Xcode_Sprite Kit_Swift3 - Fatal编程技术网

如何在iOS SpriteKit模板中重命名默认场景?

如何在iOS SpriteKit模板中重命名默认场景?,ios,swift,xcode,sprite-kit,swift3,Ios,Swift,Xcode,Sprite Kit,Swift3,我对Swift和iOS开发都是新手 我一直在开发一款基于苹果SpriteKit(与GameplayKit集成)模板的游戏 一切正常,直到我将GameSecene.swift和GameSecene.sks重命名为MapMainScene.swift和MapMainScene.sks。我确保在GameViewController.swift中更改此代码: override func viewDidLoad() { super.viewDidLoad() // Load 'GameS

我对Swift和iOS开发都是新手

我一直在开发一款基于苹果SpriteKit(与GameplayKit集成)模板的游戏

一切正常,直到我将GameSecene.swift和GameSecene.sks重命名为MapMainScene.swift和MapMainScene.sks。我确保在GameViewController.swift中更改此代码:

override func viewDidLoad() {
    super.viewDidLoad()

    // Load 'GameScene.sks' as a GKScene. This provides gameplay related content
    // including entities and graphs.
    if let scene = GKScene(fileNamed: "GameScene") {

        // Get the SKScene from the loaded GKScene
        if let sceneNode = scene.rootNode as! GameScene? {

            // Copy gameplay related content over to the scene
            sceneNode.entities = scene.entities
            sceneNode.graphs = scene.graphs

            // Set the scale mode to scale to fit the window
            sceneNode.scaleMode = .aspectFill

            // Present the scene
            if let view = self.view as! SKView? {
                view.presentScene(sceneNode)

                view.ignoresSiblingOrder = true

                view.showsFPS = true
                view.showsNodeCount = true
            }
        }
    }
}
致:

我还在
游戏场景.swift中更改了以下内容:

class GameScene: SKScene {
    // Some code
}
class MainMapScene: SKScene {
    // Some code
}
MainMapScene.swift
中执行此操作:

class GameScene: SKScene {
    // Some code
}
class MainMapScene: SKScene {
    // Some code
}
但该应用程序在启动时崩溃。控制台的输出显示:

2016-07-21 16:29:35.593592 MyGame[10656:1944648] [User Defaults] CFPrefsPlistSource<0x6080000e5e00> (Domain: kCFPreferencesAnyApplication, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null)) is waiting for writes to complete so it can determine if new data is available
2016-07-21 16:29:35.603729 MyGame[10656:1944648] [FenceWorkspace] creating a CA fence port (5d13)
2016-07-21 16:29:35.638 MyGame[10656:1944648] *** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: '*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (GameScene) for key (root); the class may be defined in source code or a library that is not linked'
*** First throw call stack:
2016-07-21 16:29:35.593592 MyGame[10656:1944648][User Defaults]CFPrefsPlistSource(域:kCFPreferencesAnyApplication,用户:kCFPreferencesCurrentUser,按主机:否,容器:(null))正在等待写入完成,以便确定新数据是否可用
2016-07-21 16:29:35.603729 MyGame[10656:1944648][FenceWorkspace]创建CA围栏端口(5d13)
2016-07-21 16:29:35.638 MyGame[10656:1944648]***由于未捕获的异常“NSInvalidUnarchiveOperationException”而终止应用程序,原因:“***-[NSKeyedUnachiver decodeObjectForKey:]:无法为键(根)解码类(游戏场景)的对象;该类可以在源代码或未链接的库中定义'
***第一次抛出调用堆栈:
因此,在我的项目中似乎仍有对
GameSecene
的引用,但我已经在项目范围内进行了搜索,没有找到
GameSecene


我相信这是非常直接的事情。我是否需要在故事板编辑器中更改插座或其他内容??我可以通过尝试在一个新项目中更改
游戏场景
的名称来重现这个问题,这样我就知道它不是我的项目特有的东西。

游戏场景
实际上在另一个地方被引用,来自
NSKeyedArchiver
的错误应该会提示您:它被编码在您正在加载的
.sks
文件中。您可以在Xcode编辑器中
.sks
文件的“自定义类”选项卡中找到它


此设置告诉
nskeyedunachiver
加载
.sks
文件时编码的场景应该是什么类。这应该是
游戏场景
的最后一次引用,因此这应该完成您的重命名

那是隐藏的地方。谢谢你救了我一天!谢谢