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.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM