SKScene not loaded when add GKComponent to GameScene.sks

我的梦境 提交于 2020-04-17 22:12:03

问题


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

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