【问题标题】:Spritekit scale full game to iPadSpritekit 将完整游戏扩展到 iPad
【发布时间】:2017-02-19 22:44:01
【问题描述】:

所以我正在使用 Spritekit 在 Xcode 上为 iPhone 开发一款游戏。通过使用 node.setScale() 方法,它在所有 iPhone 设备上看起来都一样好。现在我想让它在 iPad 上通用且可运行。我如何轻松做到这一点?量表有公式吗?

我已经尝试过的是:

if UIDevice.current.userInterfaceIdiom == .pad {
        sscale = frame.size.height / 768
    }else{
        sscale = frame.size.height / 320
    }

然后我为每个节点创建 node.setScale(sscale)。

这最终不起作用,因为在 iPad Mini 上它看起来与 iPad Air 不同......即节点大小和位置......

有什么帮助吗?

【问题讨论】:

  • 如果您愿意缩放节点(并且不太担心纵横比),您是否尝试设置 scene.scaleMode = .fill 来为您缩放所有内容?

标签: ios xcode sprite-kit


【解决方案1】:

你基本上有两个选择。

1) 将场景大小设置为 1024X768(横向)或 768x1024(纵向)并使用默认的 .aspectFill 进行缩放模式。这是 Xcode 7 中的默认设置(iPad 分辨率)。

您通常只在 iPad 上的顶部/底部(横向)或左侧/右侧(纵向)显示一些额外的背景。

在 iPad 上显示更多的游戏示例:

Altos Adventure、Leos Fortune、Limbo、The Line Zen、Modern Combat 5。

2) Apple 将 xCode 8 中的默认场景大小更改为 iPhone 6/7(750*1334-Portait、1337*750-Landscape)。此设置将裁剪您在 iPad 上的游戏。

这两个选项之间的选择取决于您,并且取决于您制作的游戏。我通常更喜欢使用选项 1 并在 iPad 上显示更多背景。

无论场景大小,缩放模式通常最好保留默认设置 .aspectFill 或 .aspectFit

要调整设备的特定内容,例如标签等,您可以这样做

 if UIDevice.current.userInterfaceIdiom == .pad {
   // adjust some UI for iPads
 }

我不会尝试在不同设备上手动更改场景或节点大小/比例的随机黑客行为,您应该让 xCode/SpriteKit 为您完成。

希望对你有帮助

【讨论】:

    【解决方案2】:

    如果您使用SKCameraNode,那么您可以通过缩放相机来缩放整个场景。

    // SKCameraNode+Extensions.swift
    extension SKCameraNode {
        func updateScaleFor(userInterfaceIdiom: UIUserInterfaceIdiom) {
            switch userInterfaceIdiom {
                case .phone:
                    self.setScale(0.75)
                case .pad:
                    self.setScale(1.0)
                default:
                    break
            }
        }
    }
    

    然后在场景初始化时调用它。

    guard let camera = self.childNode(withName: "gameCamera") as? SKCameraNode else {
        fatalError("Camera node not loaded")
    }
    
    // Update camera scale for device / orientation
    let userInterfaceIdiom = UIDevice.current.userInterfaceIdiom 
    camera.updateScaleFor(userInterfaceIdiom: userInterfaceIdiom)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多