欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

cocos2dx进阶学习之CCTMXLayer

发布时间:2024/4/14 编程问答 39 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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的派生类,所以也是一个批精灵。瓦片地图将其分成一层层的原因也是为了提高渲染的效率。

转载于:https://www.cnblogs.com/niulanshan/p/6175005.html

总结

以上是生活随笔为你收集整理的cocos2dx进阶学习之CCTMXLayer的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。