• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ios - 叠加 SKScene 未显示

[复制链接]
菜鸟教程小白 发表于 2022-10-23 05:23:42 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在尝试将 SKScene 覆盖在 SCNScene 上。当我在模拟器和 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

谢谢!



Best Answer-推荐答案


我从上面@StephenT 提到的开发者论坛中得到了这个解决方案,但我认为一些代码可能会有所帮助。

在 Xcode 提供的股票/模板代码中,Storyboard 将顶层 View 指定为 SKView,并且初始 SCNScene 应通过 SCNView 对象添加到该 View 中。这意味着当我将 SKView 添加到 SCNScene 时,我遇到了在使用 OpenGL(而不是 Metal)的任何设备上无法显示 SKView 的问题。

所以对我有用的解决方案是:
Main.storyboard -> ViewController -> view
应该设置为 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 设备以及模拟器上。

关于ios - 叠加 SKScene 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35936540/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap