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

本文为作者原创,转载请注明出处:https://www.cnblogs.com/zhaoqingqing/p/3556249.html



在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.

作者:赵青青   一名在【网易游戏】做游戏开发的程序员,擅长Unity3D,游戏开发,.NET等领域。
本文版权归作者和博客园共有,欢迎转载,转载之后请务必在文章明显位置标出原文链接和作者,谢谢。
如果本文对您有帮助,请点击【推荐】您的赞赏将鼓励我继续创作!想跟我一起进步么?那就【关注】我吧。
posted @   赵青青  阅读(12311)  评论(0编辑  收藏  举报
编辑推荐:
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· 2 本地部署DeepSeek模型构建本地知识库+联网搜索详细步骤
CONTENTS
点击右上角即可分享
微信分享提示