我正试图在SCNScene上叠加SKScene.当我在模拟器和iPhone6上运行我的应用程序时,overlayScene(SKScene)显示为预期,但是当我尝试在iPhone5上运行它(尝试了2个不同的设备)时,overlayScene不会出现.
有谁知道为什么?两个设备都在iOS 9.2.1上运行.我只测试了这两个型号的应用程序.这是我在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上面提到的开发人员论坛得到了这个解决方案,但我认为一些代码可能有所帮助.
在Xcode提供的库存/模板代码中,Storyboard将顶级视图指定为SKView,并且应通过SCNView对象将初始SCNScene添加到该视图中.这意味着当我向SCNScene添加SKView时,我遇到了一个问题,即SKView不会在任何使用OpenGL的设备上显示(而不是Metal).
所以对我有用的解决方案是:
Main.storyboard – > ViewController – >视图
应设置为SCNView,而不是SKView.
然后,在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]; }
这适用于我,在Metal和OpenGL设备以及模拟器上.