Today with the cocos2d-1.0.1-x-0.9.2 to test the tiled map function, the results found that tile flipped all disappeared, debugging code found that the original code does not support, not to x, y flip for processing, as a result, tile is flipped, so that the value is not realistic.
(Note: The latest tiled map supports flip X and flip Y. Select tile to press the X and Y keys on the disk. They are adding other rotation functions... You can download the latest version from http://www.mapeditor.org)
Modify the code to implement this function. In the cctmxlayer. cpp file, modify the appendtileforgid method:
// used only when parsing the map. useless after the map was parsed// since lot's of assumptions are no longer trueCCSprite * CCTMXLayer::appendTileForGID(unsigned int gid, const CCPoint& pos){//lancer add for tile flip //setFlipXint flip = gid>>28;int tileid = gid &0x0FFFFFFF;gid = tileid;//endCCRect rect = m_pTileSet->rectForGID(gid); rect = CCRectMake(rect.origin.x / m_fContentScaleFactor, rect.origin.y / m_fContentScaleFactor, rect.size.width/ m_fContentScaleFactor, rect.size.height/ m_fContentScaleFactor);int z = (int)(pos.x + pos.y * m_tLayerSize.width);if( ! m_pReusedTile ){m_pReusedTile = new CCSprite();m_pReusedTile->initWithBatchNode(this, rect);}else{m_pReusedTile->initWithBatchNode(this, rect);}m_pReusedTile->setPosition(positionAt(pos));m_pReusedTile->setVertexZ((float)vertexZForPos(pos));m_pReusedTile->setAnchorPoint(CCPointZero);m_pReusedTile->setOpacity(m_cOpacity);//lancer add for tile flip //setFlipXcocos2d::CCLog("---gid=%d, flip sign=%d, tileid=%d\n", gid, flip, tileid);#define TILE_FLIP_X 8#define TILE_FLIP_Y 4if(flip & TILE_FLIP_X){cocos2d::CCLog("set flip x\n");m_pReusedTile->setFlipX(true);}if(flip & TILE_FLIP_Y){cocos2d::CCLog("set flip y\n");m_pReusedTile->setFlipY(true);}//end// optimization:// The difference between appendTileForGID and insertTileforGID is that append is faster, since// it appends the tile at the end of the texture atlasunsigned int indexForZ = m_pAtlasIndexArray->num;// don't add it using the "standard" way.addQuadFromSprite(m_pReusedTile, indexForZ);// append should be after addQuadFromSprite since it modifies the quantity valuesccCArrayInsertValueAtIndex(m_pAtlasIndexArray, (void*)z, indexForZ);return m_pReusedTile;}
Author: smilelance from: http://blog.csdn.net/smilelance