Spritekit将全部游戏扩展到iPad

所以我正在使用Spritekit在iPhone上开发一个Xcode的游戏。 而且通过使用node.setScale()方法,它在所有的iPhone设备上看起来都是一样的。 现在我想把它制作成Universal,并且可以在iPad上运行。 我如何轻松做到这一点? 有规模的公式吗?

我已经试过的是这样的:

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

然后为每个节点创buildnode.setScale(sscale)。

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

任何帮助?

你基本上有2个选项。

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

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

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

阿尔托斯冒险,青奥运财富,林波,线禅,现代战争5。

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

两种select之间的select取决于你,取决于你正在做什么游戏。 我通常更喜欢使用选项1,并在iPad上显示更多背景。

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

要调整设备等特定的东西,如标签等,您可以这样做

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

我不会尝试做一些随机黑客手动更改不同设备上的场景或节点大小/尺度,你应该让xCode / SpriteKit为你做。

希望这可以帮助

如果您正在使用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)