如何使用不同的屏幕分辨率 [英] How to Work With Different Screen Resolutions

查看:37
本文介绍了如何使用不同的屏幕分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的游戏使用的是 Unity 4.3.3.我正在为 Android 和 iOS 设备制作游戏.由于我对 unity 还很陌生,我似乎无法找到一种使用不同屏幕分辨率的方法.我在我的脚本中使用 c#.

I'm using Unity 4.3.3 for my game. I'm making a game for Android and iOS devices. Since I'm pretty new to unity, I can't seem to find a way to work with different screen resolution. I'm using c# for my scripts.

我希望我的游戏全屏运行.我已经在 iPad 2 上测试过它,它运行得很好,但对于 iPhone 4,侧面被剪掉了,而对于 iPhone 5,它们被剪得更多.解决办法是什么?我应该在播放器设置 > iOS > 其他设置 > 目标分辨率下选择哪个选项?

I want my game to run full screen. I've tested it on iPad 2 and it runs perfect but for iPhone 4 the sides are clipped and for iPhone 5 they are clipped even more. What is the solution? Which option should I choose under Player Settings > iOS > OtherSettings > Target Resolution?

推荐答案

unity 更改其游戏内摄像头以匹配其所使用屏幕的纵横比尺寸.显然这并不总是需要的,所以有几种方法可以解决这个问题:

unity changes its ingame camera to match the dimensions of the aspect ratio of the screen it's using. Obviously this isn't always desired, so there's a couple of ways around this:

1) 第一种方法很容易实现,虽然它很少看起来很好.您可以简单地更改相机的纵横比以匹配您设计游戏的纵横比.因此,例如,如果您以 4:3 的速度设计游戏,您将执行以下操作:

1) First method is very easy to implement, though it rarely looks good. You can simply change the camera's aspect ratio to match the one you've designed your game around. So if for example you've designed your game at 4:3, you'd do something like this:

Camera.aspect = 4f/3f;

请记住,这会在不同的纵横比上扭曲游戏.

Just keep in mind that this will distort the game on different aspect ratios.

2) 另一种方法稍微复杂一些,但结果看起来好多了.如果您使用的是正交相机,要记住的一件重要事情是,无论使用什么屏幕分辨率,正交相机都会将高度保持在一个设定值,而只会改变宽度.例如,对于尺寸为 10 的正交相机,高度将设置为 2.考虑到这一点,您需要做的是补偿每个级别内可能最宽的相机(例如,具有更宽的背景) 或动态更改相机的正交尺寸,直到其宽度与您创建的宽度相匹配.

2) The other method is a little more complex, but the result looks much better. If you're using an orthographic camera, one important thing to keep in mind is that regardless of what screen resolution is being used, the orthographic camera keeps the height at a set value and only changes the width. For example, with an orthographic camera at a size of 10, the height will be set to 2. With this in mind what you'd need to do is compensate for the widest possible camera within each level (for example, have a wider background) or dynamically change the Orthographic Size of the camera until its width matches what you've created.

GUI 组件更容易实现,只需将它们的位置设置为依赖于任何需要的屏幕分辨率.例如,如果您希望一个按钮出现在右上角,您只需将其位置设置为类似 position = new Vector2(Screen.width - 50, 50);

GUI components are easier to implement simply by setting their position to depend on the screen resolution wherever needed. For example if you want a button to appear in the top right corner, you simply set its position to something like position = new Vector2(Screen.width - 50, 50);

既然你提到了你使用过的设备,我做了一些查找以找出每个设备使用的纵横比:Ipad2 = 4:3、Iphone4 = 3:2 和 Iphone5 = 16:9

Since you mentioned devices you used, I did a bit of looking up to find what aspect ratio each one uses: Ipad2 = 4:3 , Iphone4 = 3:2, and Iphone5 = 16:9

既然你说它在 Ipad2 上看起来很完美,我猜你已经将你的游戏设计为使用 4:3 的纵横比,所以你提到的剪辑"只是你的正交相机变宽了.解决方案是使用我上面描述的两种方法之一.

Since you said it looks perfect on the Ipad2, I'm guessing you've designed your game to use a 4:3 aspect ratio, so the "clipping" you mention is just that your orthographic camera has widened. The solution is to use one of the two methods I described above.

您可以很容易地看到它在统一编辑器中的每个设备上的外观.如果您转到游戏选项卡(在 Unity 编辑器中按播放键时弹出的内容),您会看到它有一个设备名称,以及分辨率和纵横比.更改此设置可让您查看在不同宽高比下的外观.

You can see how it will look on each device within the unity editor fairly easily. If you go to the game tab (what pops up when you press play in the unity editor), you'll see it has a device name, along with a resolution and aspect ratio. Changing this will let you see what it will look like at different aspect ratios.

这篇关于如何使用不同的屏幕分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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