Overlay SKScene is not showing

大憨熊 提交于 2019-12-05 16:53:49

I got this solution from the developer forum mentioned by @StephenT above, but I thought some code might help.

In the stock/template code provided by Xcode, the Storyboard specifies the top level view as being an SKView, and that the initial SCNScene should be added to that via an SCNView object. This meant that when I added an SKView to the SCNScene, I experienced the problem whereby the SKView would not be shown on any devices that use OpenGL (as opposed to Metal).

So the solution that works for me is:

Main.storyboard -> ViewController -> view

should be set to be an SCNView, not an SKView.

Then, in the ViewController:

- (void) viewDidLoad {
    [super viewDidLoad];

    // Configure the root view.
    //
    SCNView *scnView = (SCNView*)self.view;

    WorldSceneView *world = [[WorldSceneView alloc] initWithFrame:self.view.frame];

    // Create and configure the scene.
    //
    HUDScene *hudScene = [HUDScene hudSceneWithSize:scnView.bounds.size andHUDDelegate:world];

    // Associate the HUD SKScene with the SCNView.
    //    
    world.overlaySKScene = hudScene;

    [scnView addSubview:world];
}

This works a treat for me, on both Metal and OpenGL devices, as well as the Simulator.

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