2016-07-21 4 views
3

私はSwiftとiOS開発の両方にとても新しいです。iOS SpriteKitテンプレートのデフォルトのシーンの名前を変更するにはどうすればよいですか?

私は、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 
} 

しかし、起動時にアプリがクラッシュします。コンソールの出力は言う:私のプロジェクトでGameSceneどこかへの参照がまだあるよう

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の名前を変更しようとすると、この問題を再現できます。私のプロジェクトに固有のものではないことが分かります。

答えて

4

GameScene実際にはもう1つの場所で参照されています。NSKeyedArchiverからのエラーは、読み込み中の.sksファイルにエンコードされています。 Xcodeのエディタの.sksファイルの "Custom Class"タブで見つけることができます。

Custom Class Tab

この設定は、.sksファイルを読み込む際にエンコードされたシーンがどうあるべきか、クラスNSKeyedUnarchiver伝えます。これはGameSceneの最後の残りの参照である必要があります。これにより、名前の変更が完了します。

+0

それは隠された場所でした。ありがとう! – Garry

関連する問題