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

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

问题描述

在cocos2d-iphone中,默认投影类型是3D投影。但您也可以将投影设置为2D,如下所示:

  [[CCDirector sharedDirector] setProjection:CCDirectorProjection2D];在幕后,3D投影使用透视投影,而2D投影是OpenGL正投影。 有关这两种投影模式的技术详情,请参阅这里,即不是我感兴趣的内容。



cocos2d用户的2D投影的优点和缺点是什么?什么是切换到2D投影的好理由?



我个人使用2D投影能够对等距图块使用深度缓冲。



我还在非tilemap项目中使用了2D投影和深度缓冲,以获得完整的z通过vertexZ属性进行顺序控制。这个项目使用一个伪等距显示,其中一个对象的vertexZ是基于它的Y坐标。



这意味着我一直在使用2D投影, vertexZ属性,这也需要启用深度缓冲。

解决方案

切换到2D投影是一个救命者在下面


  • 您可以在图层中添加渲染纹理,例如,


  • 使用3D投影,纹理将用垂直和/或水平断层线渲染。例如, http://www.cocos2d-x.org/boards/6/主题/ 16197 这是cocos2d-x,但我观察到相同的效果也为cocos2d-iphone和设置投影到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];
    

    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.

    What are the benefits and drawbacks of 2D projection for cocos2d users? What are good reasons to switch to 2D projection?

    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.

    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.

    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?

    解决方案

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

    1. You create a big CCRenderTexture

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

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

    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天全站免登陆