杨宗德:cocos2dx进阶学习之CCTMXLayer


杨宗德:cocos2dx进阶学习之CCTMXLayer。

继承关系
CCTMXLayer -> CCSpriteBatchNode
CCTMXLayer是在瓦片地图中,抽象一个层的类,它继承自CCSpriteBatchNode,也就是说它抽象了一批相同图片的精灵,在瓦片地图中,用层来抽象她们。

成员函数
CCSprite* tileAt(const CCPoint& tileCoordinate);
获取该坐标的精灵,这里的坐标是网格坐标

unsigned int  tileGIDAt(const CCPoint& tileCoordinate);
获取该网格坐标的GID

void setTileGID(unsigned int gid, const CCPoint& tileCoordinate);
void setTileGID(unsigned int gid, const CCPoint& tileCoordinate, ccTMXTileFlags flags);
设置该点的GID

void removeTileAt(const CCPoint& tileCoordinate);
删除tile

CCPoint positionAt(const CCPoint& tileCoordinate);
坐标转化

CCString *propertyNamed(const char *propertyName);
属性值

void setupTiles();
创建瓦片

virtual void addChild(CCNode * child, int zOrder, int tag);
这个接口在Layer里不支持,在这里重载是为了报错

void removeChild(CCNode* child, bool cleanup);
删除子对象

inline const char* getLayerName(){ return m_sLayerName.c_str(); }
inline void setLayerName(const char *layerName){ m_sLayerName = layerName; }
设置和获取Layer名字

总结
CCTMXLayer是CCSpriteBatchNode的派生类,所以也是一个批精灵。瓦片地图将其分成一层层的原因也是为了提高渲染的效率。

杨宗德:cocos2dx进阶学习之CCTMXLayer。了解更多关于网络编程问题,就在良师益友网。http://www.elsyy.com/course/lesson-6945