roguelike2d 摄像机参数设置
来源:互联网 发布:穿越火线抽奖软件 编辑:程序博客网 时间:2024/06/05 10:23
基于回合制的、基于瓦片地图的、roguelike的2d的scavenger游戏项目,其中摄像机的设置参数值在视频教程中并没有说明如何计算出来的。Hoxily尝试修改棋盘的rows和columns值的时候,游戏画面就不对了。
首先设置摄像机的目标是将棋盘恰好不漏包含在游戏画面中。
然后注意到资源中的sprite导入参数是32像素每单位长度,每个sprite恰好是1个单位的长与宽。
摄像机处于orthographics正投影时,Size参数控制的是摄像机的一半高度。而摄像机的宽度则由屏幕的宽高比和摄像机的高度两个因素确定。
sprite的transform.position是该sprite的正中位置。
因此计算摄像机参数过程如下:
using UnityEngine;using System.Collections;[RequireComponent(typeof(Camera))]public class CameraManager : MonoBehaviour{private Camera _camera;void Awake (){_camera = GetComponent<Camera> ();}/// <summary>/// 根据棋盘的大小,自动计算出相机的orthographicsSize,以及transform位置/// </summary>/// <param name="columns">Columns.</param>/// <param name="rows">Rows.</param>public void SetupCamera (int columns, int rows){float boardHeight = rows + 2;float boardWidth = columns + 2;float boardAspectRatio = boardWidth / boardHeight;float screenAspectRatio = (float)Screen.width / (float)Screen.height;if (boardAspectRatio <= screenAspectRatio) {// black strip at left and right// orthographicsSize * 2 == boardHeight_camera.orthographicSize = boardHeight / 2f;} else {// black strip at up and down// orthographicsSize * 2 * screenRation == boardWidth_camera.orthographicSize = boardWidth / screenAspectRatio / 2f;}float x = Center (-1f, -1f + boardWidth) - 0.5f;float y = Center (-1f, -1f + boardHeight) - 0.5f;float z = transform.position.z;transform.position = new Vector3 (x, y, z);}float Center (float min, float max){return (min + max) / 2f;}}
0 0
- roguelike2d 摄像机参数设置
- 参数设置
- 摄像机
- 摄像机
- 摄像机
- 摄像机
- 摄像机
- 摄像机
- 摄像机
- 摄像机
- 摄像机
- mysql 参数设置
- sybase参数设置
- RenderingHints 参数设置
- ffmpeg参数设置
- Apache参数设置
- ffmpeg参数设置
- ActionServlet参数设置
- C++中的typedef
- 从存储角度看大数据和云计算区别与联系
- MySQL跳过密码登录
- 基本图形生成算法
- Java基础知识
- roguelike2d 摄像机参数设置
- hdoj4883TIANKENG’s restaurant(贪心)
- 39节课后再解
- centos7 yum install php php-fpm
- C#中arraylist的使用
- JSTL标签库
- ProgressBar 深入分析
- 关于android中有可能出现使用按钮出现空指针的一种解答
- Microsoft Smooth Streaming协议环境配置