创建多个SKS文件与使用if语句确定屏幕大小

时间:2016-03-06 11:30:51

标签: iphone swift ipad sprite-kit ios-universal-app

我一整天都在研究如何正确实施iPhone和Case Ipad尺寸。有些人使用辅助类来“缩放”或“适应”SpriteKit场景到GVC中的正确视图。我正在寻找方向因为它有点令人困惑。首先你在GVC中有这个选项:

if (UIDevice.currentDevice().userInterfaceIdiom == .Pad) {

        if let scene = Page(fileNamed:"Cover") {
            // Configure the view.
            let skView = self.view as! SKView
            skView.showsFPS = false
            skView.showsNodeCount = false

            /* Sprite Kit applies additional optimizations to improve rendering performance */
            skView.ignoresSiblingOrder = true

            /* Set the scale mode to scale to fit the window */
            scene.scaleMode = .AspectFill
            scene.currentPage = "Cover"

            skView.presentScene(scene)
        }


    } else {

        if let scene = Page(fileNamed:"CoverPhone") {
            // Configure the view.
            let skView = self.view as! SKView
            // skView.showsFPS = true
            //skView.showsNodeCount = true

            /* Sprite Kit applies additional optimizations to improve rendering performance */
            skView.ignoresSiblingOrder = true

            /* Set the scale mode to scale to fit the window */
            scene.scaleMode = .AspectFill
            scene.currentPage = "Cover"
            skView.presentScene(scene)


        } else if let scene = Page(fileNamed:"Cover") {
            // Configure the view.
            let skView = self.view as! SKView
            skView.showsFPS = true
            skView.showsNodeCount = true

            /* Sprite Kit applies additional optimizations to improve rendering performance */
            skView.ignoresSiblingOrder = true

            /* Set the scale mode to scale to fit the window */
            scene.scaleMode = .AspectFill
            scene.currentPage = "Cover"
            skView.presentScene(scene)
        }


    }




}

这是我的理解(代码复制自CartoonSmart,StoryTeller Bundle v.1.10。所以我会为.phone one .pad制作两个SkS文件并配置场景,从GVC调用适当的场景。

然后我看到这些冗长的陈述:一个“小”片段......

if (platform == "iPad2,4") {
    return "iPad 2 (WiFi)"
}
if (platform == "iPad3,1") {
    return "iPad 3 (WiFi)"
}
if (platform == "iPad3,2") {
    return "iPad 3 (GSM+CDMA)"
}
if (platform == "iPad3,3") {
    return "iPad 3 (GSM)"
}
if (platform == "iPad3,4") {
    return "iPad 4 (WiFi)"
}
if (platform == "iPad3,5") {
    return "iPad 4 (GSM)"   

Gist for device types

这到底在哪里,目的究竟是什么?

我的理由是,对于iPhone,我使用的是1080 x 1080,因为使用纵横填充缩放图像时,@ 2x分辨率可以正确优化并且看起来很棒。同时为Apple TV提供便携性。

如果我创建两个sks文件,我需要为iPad sks文件复制子类等,或者是一种利用iPhone类的方法,而不必复制控制场景中节点的.swift文件。考虑到我使用全局/基本场景来处理导航和其他全局属性。

0 个答案:

没有答案