Spritekit 将完整游戏扩展到 iPad [英] Spritekit scale full game to iPad

查看:20
本文介绍了Spritekit 将完整游戏扩展到 iPad的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

So I'm developing a game on Xcode using Spritekit, for the iPhone. And it looks all the same and great on all iPhone devices, by using the node.setScale() method. Now I want to make it Universal and runnable on the iPad as well. How do I do this easily? Is there some formula for the scale?

我已经尝试过的是:

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

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

And then for every node I make node.setScale(sscale).

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

This ends up not working because on the iPad Mini it looks different from the iPad Air... i.e node sizes and positions...

有什么帮助吗?

推荐答案

你基本上有两个选择.

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

1) Set scene size to 1024X768 (landscape) or 768x1024 (portrait) and use the default .aspectFill for scale mode. This was the default setting in Xcode 7 (iPad resolution).

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

You than usually just show some extra background at the top/bottom (landscape) or left/right (portrait) on iPads.

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

Examples of games that show more on iPads:

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

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 上的游戏.

2) Apple changed the default scene size in xCode 8 to iPhone 6/7 (750*1334-Portait, 1337*750-Landscape). This setting will crop your game on iPads.

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

Chosing between the 2 options is up to you and depends what game you are making. I usually prefer to use option 1 and show more background on iPads.

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

Regardless of scene size scale mode is usually best left at the default setting of .aspectFill or .aspectFit

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

To adjust specific things such as labels etc for a device you can do it this way

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

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

I would not try to do some random hacks where you manually change scene or node sizes/scales on difference devices, you should let xCode/SpriteKit do it for you.

希望对你有帮助

这篇关于Spritekit 将完整游戏扩展到 iPad的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆