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

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

问题描述

我使用Unity 4.3.3为我的比赛。我在做一个游戏为Android和iOS设备。因为我是pretty的新的团结,我似乎无法找到一种方法,用不同的屏幕分辨率达到了工作。 我使用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> OtherSettings>目标分辨率?

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 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组件更容易通过设置自己的位置需要的地方依赖于屏幕分辨率来实现简单。例如,如果你想有一个按钮出现在右上角,你只需将它的位置,像位置=新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.

您可以看到它的外观统一编辑器中每个设备上相当容易。如果你去游戏选项卡(什么时弹出preSS发挥团结编辑器),你会看到它有一个设备名称,以及一个分辨率和宽高比。改变这种状况,让你看到它的样子,在不同的纵横比。

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天全站免登陆