覆盖SKScene没有显示 [英] Overlay SKScene is not showing
问题描述
我正试图在SCNScene上叠加SKScene。当我在模拟器和iPhone6 +上运行我的应用程序时,overlayScene(SKScene)显示为预期,但当我尝试在iPhone5上运行它(尝试了2个不同的设备)时,overlayScene不会出现。
I'm trying to overlay an SKScene over a SCNScene. When I run my app on the simulator and an iPhone6+, the overlayScene(SKScene) is shown as intended, but when I tried running it on the iPhone5 (tried 2 different devices) the overlayScene does not appear.
有谁知道为什么?两个设备都在iOS 9.2.1上运行。我只测试了这两个型号的应用程序。这是我在GameViewController.Swift中的代码
Does anyone have an idea why? Both device run on iOS 9.2.1. I have only tested the app on those two models. Here's my code inside the GameViewController.Swift
//Configure the view
sceneView = self.view as? SCNView
//Configure the scene
sceneView.scene = gameScene
sceneView.playing = true
sceneView.backgroundColor = UIColor.blackColor()
sceneView.antialiasingMode = SCNAntialiasingMode.Multisampling4X
let overlayScene = OverlayScene(size: self.view.bounds.size)
sceneView.overlaySKScene = overlayScene
谢谢!
推荐答案
我从这里得到了这个解决方案@StephenT上面提到的开发人员论坛,但我认为一些代码可能会有所帮助。
I got this solution from the developer forum mentioned by @StephenT above, but I thought some code might help.
在Xcode提供的股票/模板代码中,Storyboard将顶级视图指定为一个SKView,并且应该通过SCNView对象添加初始SCNScene。这意味着当我向SCNScene添加SKView时,我遇到了一个问题,即SKView不会在任何使用OpenGL的设备上显示(而不是Metal)。
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
应该设置为SCNView,而不是SKView。
should be set to be an SCNView, not an SKView.
然后,在ViewController中:
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];
}
这对我来说也适用于金属和OpenGL设备作为模拟器。
This works a treat for me, on both Metal and OpenGL devices, as well as the Simulator.
这篇关于覆盖SKScene没有显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!