zoukankan      html  css  js  c++  java
  • cocoa2dx tiled map添加tile翻转功能

             今天用cocos2d-1.0.1-x-0.9.2来测试tiled map的功能,结果发现翻转过的tile都不见了,调试代码发现原来代码里不支持,没有对x,y翻转作处理,结果翻转过的tile导致数值多大没有被现实出来。

            ( 注:最新的Tiled map已经支持flip x和flip y,选中tile按键盘上x键,y键即可,其他旋转功能他们正在添加中。。。最新版本可以从http://www.mapeditor.org/下载)

              修改代码实现此功能,  CCTMXLayer.cpp文件里针对appendTileForGID方法作出修改,上代码:


             // used only when parsing the map. useless after the map was parsed
    	// since lot's of assumptions are no longer true
    	CCSprite * CCTMXLayer::appendTileForGID(unsigned int gid, const CCPoint& pos)
    	{
    		//lancer add for tile flip //setFlipX
    		int flip = gid>>28;
    		int tileid =  gid &0x0FFFFFFF;
    		gid = tileid;
    		//end
    		
    		CCRect 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 //setFlipX
    		cocos2d::CCLog("---gid=%d, flip sign=%d, tileid=%d\n", gid, flip, tileid);
    #define TILE_FLIP_X 8
    #define TILE_FLIP_Y 4	
    		if(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 atlas
    		unsigned 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 values
    		ccCArrayInsertValueAtIndex(m_pAtlasIndexArray, (void*)z, indexForZ);
    
    
    		return m_pReusedTile;
    	}
           

     PS:转载请保留以下信息
    Author:smilelance    


          

  • 相关阅读:
    layui第三方组件运用
    layui select lay-filter就不渲染和全局渲染用法和校验
    layui 点击操作列后背景色去掉
    layui混合案列问题
    使用layui富文本添加日志内容,并获取子窗体的富文本内容
    layu tab切换table
    layui 父窗体传子窗体select动态选中
    jstl过长的内容处理空格以及换行并通过js处理内容自动换行
    js中运用jstl标签解决checked是否选中等问题
    javaMD5实现加密解密
  • 原文地址:https://www.cnblogs.com/secbook/p/2655401.html
Copyright © 2011-2022 走看看