Unity2D 背景图铺满与Camera.Size的计算公式

在unity制作2D游戏的教程,背景图sprite铺满显示时Camaer的Size调到多少合适,作个笔记。

资源参数

background.png 2048x640,Sprite的像素单位:100

imageimage

调节camera.size

当camera的size=5,背景的显示效果

imageimage

Camera的Size=3.2的背景的显示效果

image

 

计算公式 

计算公式为:Screen Height/2/Pixel To Units=Main Camera.Size

对于2048x640的背景图,像素为100单位的比例,Camera的Size=640/2/100=3.2

For example, consider a Sprite imported from a 500 pixels wide image. The following table shows the different widths your GameObject would have when rendering that Sprite at different scales along the x-axis, using different values for Pixels to Units:

size comparisons with varying scales and pixels to units

background.png is 640 pixels tall, and the background Sprite has a Pixel to Unit ratio of 100, so the backgroundobject in the Hierarchy will be 6.4 units tall. However, the orthographic camera’s Size property measures half the height of the screen, so it should be half the height of the background, in units, or 3.2.

posted @ 2014-02-19 16:55  赵青青  阅读(12189)  评论(0编辑  收藏  举报