@riq: I did it with vertexZ! I just had to enable GL_Blend and GL_Alpha_Test when enabling GL_Depth_TEST. However, I had to add the following 2 lines also in setDepthTest:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - best used for back to front rendering
glAlphaFunc(GL_GREATER, 0.0f); - also used to help render the alpha of the images from back to front.
It works great, and it works with Projection 2D or Projection 3D.
I have also created 3 new classes called: CCTMXIsoLayer, CCTMXIsoTiledMap, and CCTMXIsoObject. Due note that even though it is called CCTMXIsoLayer it can be used with Orthagonal also, and will probably benefit from the vertexZ also, but I haven't tested with Orthagonal yet.
CCTMXIsoLayer and CCTMXIsoTiledMap work just like CCTMXLayer and CCTMXTiledMap, but uses some new methods to set the vertexZ starting at 1 and increases based on the tile position, and the layer number. Layer number starts at 0 and goes up based on how many layers are in the TMX file.
Then the CCTMXIsoObject is quite generic it is a Subclass of CCSpriteSheet, but has the following methods:
setObjectSprite:(CCSprite *) sprite; - This allows the developer to subclass the CCTMXIsoObject and still use their own sprite / sprite sheet / init methods. Just be sure to use setObjectSprite after creating the sprite, because the Sprite reference is needed in setObjectPosition.
setObjectPosition:(CGPoint) pos; - The position is not in pixels but in the number of tiles. Updates the vertexZ order of IsoObject and surrounding tiles in the following directions: Bottom Left, Bottom Right, Bottom, Top, Top Left, Top Right. Left and Right are not needed to update because of vertexZ based on x, y of tile.
setTileMap:(CCTMXIsoTiledMap *) tilemap; - the object requires this reference so it knows which map to access so it can update the surrounding vertexZ of tiles on setObjectPosition.
Has the available readwrite property: int objectLayer - this allows you to set base layer the object is suppose to be on.
setObjectPosition will automatically go through all layers above the specified objectLayer and update the tiles surrounding the object. The object will finally end up with the vertexZ of the objectLayer or the vertexZ of one layer above it.
I will post the zip file containing the IsoTileTest project I created tomorrow. I need to go through and add comments to the code so it conforms to cocos2d standards. You will find the 3 new CCTMXIso classes in the Cocos2d src folder. Then the testing classes are under Classes folder.
Basically, you will need to come up with your own path finding algorithm for isometric tiles. You will need to move the sprite 1 tile at a time and use setObjectPosition so that the object will properly look like it is moving behind / infront of other tiles / object while moving.
The CCTMXIsoObject class is generic enough to be used for any object / NPC / Main Character / Whatever.
I have tested it in all possible position on the map and it works properly in the test app. I have also tested it for memory leaks and there appear to be none, besides some of apples.
You will have to change the moveTo of TestHero under helloworld.m to see the object in different tile positions. The moveTo of TestHero is based on Tile coord and not pixels.