Cocoa2d-x tiled map added tile flip Function

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.