本文来自http://blog.csdn.net/runaying ,引用必须注明出处!
温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记
和 CCTMXXMLParser(//cocos2d-x-3.0alpha0/cocos2dx/tilemap_parallax_nodes/CCTMXXMLParser.h)类差不多都是解析地图
//cocos2d-x-3.0alpha0/cocos2dx/tilemap_parallax_nodes/ //和 CCTMXXMLParser(//cocos2d-x-3.0alpha0/cocos2dx/tilemap_parallax_nodes/CCTMXXMLParser.h) 类差不多都是解析地图 #ifndef __CCTMX_TILE_MAP_H__ #define __CCTMX_TILE_MAP_H__ #include "base_nodes/CCNode.h" #include "CCTMXObjectGroup.h" NS_CC_BEGIN class TMXObjectGroup; class TMXLayer; class TMXLayerInfo; class TMXTilesetInfo; class TMXMapInfo; /** * @addtogroup tilemap_parallax_nodes * @{ */ /** TMX地图可能的方向 */ enum { /** 正交方向 */ TMXOrientationOrtho, /** 六角方向 */ TMXOrientationHex, /** 等距方向 */ TMXOrientationIso, }; /** @brief TMXTiledMap 知道如何解析和渲染TMX地图 它增加了的 TMX tiled 的地图所使用的格式 http://www.mapeditor.org 它支持等距,六角形和正交瓷砖。 tiles. 它还支持对象组,对象和属性。 特点: - 把每个 tile 当作 Sprite 对待 - sprites 根据需求创建. 只有当你调用 "layer->tileAt(position)" 它们才会被创建 - 每个 tile 都可以 rotated / moved / scaled / tinted / "opaqued", 因为每个 tile 都是一个 Sprite - 在运行时可以 added/removed Tiles - teles 的 z-order 可以在运行时修改 - 每个 tile 都有一个 anchorPoint (0,0) //锚点 - TMXTileMap 的 anchorPoint 是 (0,0) //锚点 - TMX layers will be added as a child - The TMX layers will be aliased by default //别名 - 地形设置的图像将使用 TextureCache 载入 - 每个 tile 都将有一个独特的 tag - 每个 tile 都将有一个独特的 z value. top-left: z=1, bottom-right: z=max z - 每个对象组将被视为MutableArray - Object类包含字典中的所有属性 - 可以分配到的 the Map, Layer, Object Group, and Object 属性 限制: - 每一个 layer 只支持一种地形设置. - 不支持嵌入式图像 - 它只支持XML格式(JSON格式不支持) 技术说明: 每一个 layer 都使用一个 TMXLayer (SpriteBatchNode的子类)创建. 如果你有 5 个 layers, 那么会有 5 个 TMXLayer 被创建, 除非 layer 不可见,在这种情况下,该 layer 将不被创建 你可以在运行时通过下面的方式获得 layers (TMXLayer objects) : - map->getChildByTag(tag_number); // 0=1st layer, 1=2nd layer, 2=3rd layer, etc... - map->getLayer(name_of_the_layer); 每一个 object group 都适用一个 TMXObjectGroup 他是 MutableArray 的子类. 你可以在运行时通过下面的方式获得 object groups: - map->getObjectGroup(name_of_the_object_group); 每一个对象都是一个 TMXObject. 每个属性都使用 键/值 存储在一个MutableDictionary 里面 你可以在运行时通过下面方式获得属性: map->getProperty(name_of_the_property); layer->getProperty(name_of_the_property); objectGroup->getProperty(name_of_the_property); object->getProperty(name_of_the_property); @since v0.8.1 */ class CC_DLL TMXTiledMap : public Node { public: /** * @js ctor */ TMXTiledMap(); /** * @js NA * @lua NA */ virtual ~TMXTiledMap(); /** 使用 TMX文件 创建一个 TMX Tiled Map .*/ static TMXTiledMap* create(const char *tmxFile); /** 使用 TML格式的 XML 字符串,TMX资源路径 初始化一个 TMX Tiled Map */ static TMXTiledMap* createWithXML(const char* tmxString, const char* resourcePath); /** 使用 TMX文件 初始化一个 TMX Tiled Map */ bool initWithTMXFile(const char *tmxFile); /** 使用 TML格式的 XML 字符串,TMX资源路径 初始化一个 TMX Tiled Map */ bool initWithXML(const char* tmxString, const char* resourcePath); /** return the TMXLayer for the specific(特定的) layer */ TMXLayer* getLayer(const char *layerName) const; /** * @js NA * @lua NA */ CC_DEPRECATED_ATTRIBUTE TMXLayer* layerNamed(const char *layerName) const { return getLayer(layerName); }; /** return the TMXObjectGroup for the specific(特定) group */ TMXObjectGroup* getObjectGroup(const char *groupName) const; /** * @js NA * @lua NA */ CC_DEPRECATED_ATTRIBUTE TMXObjectGroup* objectGroupNamed(const char *groupName) const { return getObjectGroup(groupName); }; /** return 特定的属性名的值 */ String *getProperty(const char *propertyName) const; /** * @js NA * @lua NA */ CC_DEPRECATED_ATTRIBUTE String *propertyNamed(const char *propertyName) const { return getProperty(propertyName); }; /** return tile 属性字典的 GID */ Dictionary* getPropertiesForGID(int GID) const; CC_DEPRECATED_ATTRIBUTE Dictionary* propertiesForGID(int GID) const { return getPropertiesForGID(GID); }; /** map's 的尺寸属性使用 tiles 测量 */ inline const Size& getMapSize() const { return _mapSize; }; inline void setMapSize(const Size& mapSize) { _mapSize = mapSize; }; /** tiles's 的尺寸属性使用 pixels(像素)测量 */ inline const Size& getTileSize() const { return _tileSize; }; inline void setTileSize(const Size& tileSize) { _tileSize = tileSize; }; /** 地图方向 */ inline int getMapOrientation() const { return _mapOrientation; }; inline void setMapOrientation(int mapOrientation) { _mapOrientation = mapOrientation; }; /** object groups */ inline Array* getObjectGroups() const { return _objectGroups; }; inline void setObjectGroups(Array* groups) { CC_SAFE_RETAIN(groups); CC_SAFE_RELEASE(_objectGroups); _objectGroups = groups; }; /** properties */ inline Dictionary* getProperties() const { return _properties; }; inline void setProperties(Dictionary* properties) { CC_SAFE_RETAIN(properties); CC_SAFE_RELEASE(_properties); _properties = properties; }; private: TMXLayer * parseLayer(TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo); TMXTilesetInfo * tilesetForLayer(TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo); void buildWithMapInfo(TMXMapInfo* mapInfo); protected: /** map's 的尺寸属性使用 tiles 测量 */ Size _mapSize; /** tiles's 的尺寸属性使用 pixels(像素)测量 */ Size _tileSize; /** 地图方向 */ int _mapOrientation; /** object groups */ Array* _objectGroups; /** properties */ Dictionary* _properties; //! tile properties Dictionary* _tileProperties; }; // end of tilemap_parallax_nodes group /// @} NS_CC_END #endif //__CCTMX_TILE_MAP_H__