使用 cocos2d-iphone 启用 2D 投影的充分理由是什么? [英] What are good reasons to enable 2D projection with cocos2d-iphone?

查看:17
本文介绍了使用 cocos2d-iphone 启用 2D 投影的充分理由是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 cocos2d-iphone 中默认的投影类型是3D"投影.但您也可以像这样将投影设置为2D":

In cocos2d-iphone the default projection type is "3D" projection. But you can also set the projection to "2D" like so:

[[CCDirector sharedDirector] setProjection:CCDirectorProjection2D];

在幕后,3D 投影使用透视投影,而 2D 投影是 OpenGL 正交投影.这两种投影模式的技术细节可以在这里查看,那是不是我感兴趣的东西.

Behind the scenes the 3D projection uses perspective projection whereas 2D projection is the OpenGL orthographic projection. The technical details about these two projection modes can be reviewed here, that's not what I'm interested in.

2D投影对于cocos2d用户有什么好处和坏处?切换到 2D 投影的充分理由是什么?

就我个人而言,我使用 2D 投影能够将深度缓冲用于等距平铺地图.等距平铺地图需要此功能才能正确在平铺地图上对平铺和对象进行 z 排序.

Personally I've used 2D projection to be able to use depth buffering for isometric tilemaps. Isometric tilemaps require this for correct z ordering of tiles and objects on the tilemap.

我还在非 tilemap 项目中使用了带有深度缓冲的 2D 投影,以通过 vertexZ 属性获得完整的 z 顺序控制.该项目使用伪等距显示,其中对象的 vertexZ 基于其 Y 坐标.

I've also used 2D projection with depth buffering in non-tilemap projects to get complete z order control via the vertexZ property. This project used a pseudo isometric display where the vertexZ of an object is based on its Y coordinate.

这意味着我一直使用 2D 投影只是为了能够使用 vertexZ 属性,这也需要启用深度缓冲.是否还有其他原因可能希望切换到 2D 投影?

That means I've been using 2D projection only to be able to use the vertexZ property, which also requires enabling depth buffering. Are there any other reasons one might want to switch to 2D projection?

推荐答案

在以下场景中切换到 2D 投影是救命稻草:

Switching to 2D projection is a life saver in the following scenario:

  1. 你创建了一个大的 CCRenderTexture

  1. You create a big CCRenderTexture

你在上面画了一堆东西,要么使用 [...访问] 要么使用 OpenGL 绘图函数

You draw a bunch of stuff on it, either using [... visit] or OpenGL drawing functions

您将渲染纹理添加到您的图层,例如,为了将您在第 2 点中绘制的东西用作游戏的背景.

You add the render texture to your layer, e.g., in order for the things you drew in point 2. to serve as the background for your game.

使用 3D 投影,将使用垂直和/或水平断层线渲染纹理.参见例如 http://www.cocos2d-x.org/boards/6/topic/16197 适用于 cocos2d-x,但我观察到 cocos2d-iphone 也有相同的效果,并将投影设置为 2D 解决了这个问题.

With 3D projection, the texture will be rendered with vertical and/or horizontal fault lines. See e.g., http://www.cocos2d-x.org/boards/6/topics/16197 which is for cocos2d-x but I have observed the same effect also for cocos2d-iphone and setting the projection to 2D got rid of the problem.

这篇关于使用 cocos2d-iphone 启用 2D 投影的充分理由是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆