Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am following this guide:

http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:tiled_maps

Trying to create a tiled map that also supports multiple layers. The guide says that a way is to use depth buffer, and says to:

1) Create the z-buffer and a 2D projection; 2) For every layer in the tiled map, set the cc_vertexz attribute; 3) Enable alpha test and set the sprite alpha func.

The first question is: if I use a tiled maps with multiple layers, are also the point 1 and 3 needed?

I am fine with the first two points, but as for the third point I don't know how to do that. I should subclass CCSprite and override the draw method, but the problem is that when I create a tiled map there are already sprites on it, so the instances don't belong to the subclass I created. How I go around this?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

There are 2 methods described in the guide, Using multiple TMX Layers and z-order and Using Depth Buffer. It would be better to use Using multiple TMX Layers and z-order as it is easier to use and it uses cocos2d's drawing and z-order structure.

1) is not needed as every tile in CCTMXTiledMap is a CCSprite, where the order of rendering depends on the z-order of CCSprite. Using multiple TMX Layers and z-order has described how it works.

2) cc_vertexz is the value of a z axis value of a vertex in a 3d space. If you are using z-order you don't need to set cc_vertexz at all. You should not set cc_vertexz if you are using cocos2d v2.0. An exception would raise if you use it as it is no longer support.

3) Again, the alpha test is not needed if you are using z-order. CCTMXLayer has already enabled it by default.

If you insist on using Using Depth Buffer, 1) 2) and 3) are required. You can override CCTMXLayer/CCSpriteBatchNode's draw to enable the alpha test before [textureAtlas_ drawQuads];, instead of every CCSprite. The order of CCSprite is not important because z-buffer is enabled.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.