如何使 SKScene 具有固定宽度? [英] How to make SKScene have fixed width?

查看:17
本文介绍了如何使 SKScene 具有固定宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个基于 spriteKit 的游戏,我想知道我是否可以让 SKScene 固定宽度(以便更容易布局精灵),并让它在保持纵横比的同时调整到实际屏幕宽度.是否有可能实现这个目标,是否推荐(由于调整大小,精灵会不会被清晰地渲染)?

I am making a spriteKit based game and wonder if I can make the SKScene fixed width (to make it easier to layout the sprites), and let it resize to the actual screen width while keeping the aspect ratio. Is it possible to achieve this goal and is it recommended (will sprites not be rendered clearly due to resizing)?

推荐答案

给场景一个固定大小实际上是我们想要在 SpriteKit 游戏中做的事情.SpriteKit 将使用 scaleMode 设置(默认为 .aspectFill)为每个设备缩放游戏.将场景设置为设备大小或使用 .resizeFill 进行缩放模式并不是一个好主意,因为这会导致不同设备上的大量不一致.我以前参加过一场比赛,那绝对是一场噩梦.

Giving the scene a fixed size is actually what we want to do in SpriteKit games. SpriteKit will than scale the game for each device using the scaleMode settings (defaults to .aspectFill). Its not a good idea to make the scene the size of the device or use .resizeFill for scale mode as that will lead to massive inconsistencies on different devices. I have been there before with 1 game and it was an absolute nightmare.

所以我们基本上有两种方法可以正确地做到这一点

So we basically have 2 ways to do it correctly

1) 将场景大小设置为 iPad(例如 1024x768 - 横向,768x1024 - 纵向.这是 Xcode 7 中的默认设置.

1) Set scene size to iPad (e.g 1024x768 -landscape, 768x1024 - portrait. This was the default setting in Xcode 7.

您通常只在 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.

在 iPad 上显示较少的游戏示例:

Examples of games that show less on iPads:

Lumino City,机器人独角兽攻击

Lumino City, Robot Unicorn Attack

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

Choosing between those 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.这样您就可以在所有设备上获得一致的体验.

Regardless of scene size scale mode is usually best left at the default setting of .aspectFill. This way you will have a consistent experience on all devices.

我不会尝试在不同设备上手动更改场景或节点大小/比例的随机黑客行为,您应该让 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.

在代码中,您将使用您喜欢的大小初始化一个 SKScene,如下所示

In code you would initialise a SKScene with your preferred size like so

let gameScene = GameScene(size: CGSize(width: 1024, height: 768))

如果您使用视觉场景编辑器,您可以直接在右侧的检查器面板中设置场景大小.

If you use the visual scene editor you set the scene size directly in the inspector panel on the right.

希望对你有帮助

这篇关于如何使 SKScene 具有固定宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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