我对Swift和iOS开发都是新手。
我一直在开发基于Apple SpriteKit(与GameplayKit集成)模板的游戏。
一切正常,直到我将GameScene.swift和GameScene.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
}
}
}
}
至:
override func viewDidLoad() {
super.viewDidLoad()
// Load 'MainMapScene.sks' as a GKScene. This provides gameplay related content
// including entities and graphs.
if let scene = GKScene(fileNamed: "MainMapScene") {
// Get the SKScene from the loaded GKScene
if let sceneNode = scene.rootNode as! MainMapScene? {
// 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
}
}
}
}
我还更改了以下内容Gamescene.swift
:
class GameScene: SKScene {
// Some code
}
为此MainMapScene.swift
:
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:
因此,看起来GameScene
我的项目中仍然有对某处的引用,但是我已经在项目范围内进行了搜索,因此找不到GameScene
任何地方。
我敢肯定,这确实很简单。我是否需要在情节提要编辑器中更改插座或其他内容?我也可以通过尝试GameScene
在新项目中更改名称来重现此问题,因此我知道这不是我的项目所特有的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句