问题
I am currently creating a 2D game with Swift SpriteKit and GameplayKit. I have a GameScene.sks file and a GameScene.swift file that is of type SKScene. Now I wanted to add a Component of type GKComponent. I created my component and added it to one of my SKSpriteNodes in GameScene.sks
However after adding the Component to the SpriteNode in the Scene Editors Inspector the Scene is no longer loaded and the app shows only a grey screen.
Is this a known issue in XCode? Is there a way of bypassing this issue?
I have not uploaded any example code. The issue is reproducable by any new XCode Project (ios / Game) that supports SpriteKit and GameplayKit. Just add a class that is derived from GKComponent and add the class to the given helloLabel in the Scene Editor.
This is how the GameScene is loaded:
class GameViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
if let scene = GKScene(fileNamed: "GameScene") {
if let sceneNode = scene.rootNode as! GameScene? {
// This gets only executed when I remove the Component from the SKSpriteNode in the Scene Editor.
}
}
...
来源:https://stackoverflow.com/questions/60449011/skscene-not-loaded-when-add-gkcomponent-to-gamescene-sks