代码:
class CC_DLL TMXTiledMap : public Node
{
public:
/** Creates a TMX Tiled Map with a TMX file.
*
* @return An autorelease object.
*/
/// 创建一个TMX 瓦片地图,通过tmx文件
static TMXTiledMap* create(const std::string& tmxFile);
/** Initializes a TMX Tiled Map with a TMX formatted XML string and a path to TMX resources.
*
* @param tmxString A TMX formatted XML string.
* @param resourcePath A path to TMX resources.
* @return An autorelease object.
*/
/// 通过xml创建一个瓦片地图
static TMXTiledMap* createWithXML(const std::string& tmxString, const std::string& resourcePath);
/** Return the FastTMXLayer for the specific layer.
*
* @return Return the FastTMXLayer for the specific layer.
*/
/// 得到TXMLLayer通过名字
TMXLayer* getLayer(const std::string& layerName) const;
/** Return the TMXObjectGroup for the specific group.
*
* @return Return the TMXObjectGroup for the specific group.
*/
/// 得到TMXObjectGroup,通过制定的组
TMXObjectGroup* getObjectGroup(const std::string& groupName) const;
/** Return the value for the specific property name.
*
* @return Return the value for the specific property name.
*/
/// 得到特性的值
Value getProperty(const std::string& propertyName) const;
/** Return properties dictionary for tile GID.
*
* @return Return properties dictionary for tile GID.
*/
/// 通过GID得到特性的值
Value getPropertiesForGID(int GID) const;
/** The map's size property measured in tiles.
*
* @return The map's size property measured in tiles.
*/
/// 得到地图的尺寸
inline const Size& getMapSize() const { return _mapSize; };
/** Set the map's size property measured in tiles.
*
* @param mapSize The map's size property measured in tiles.
*/
/// 设置地图的尺寸
inline void setMapSize(const Size& mapSize) { _mapSize = mapSize; };
/** The tiles's size property measured in pixels.
*
* @return The tiles's size property measured in pixels.
*/
/// 得到瓦片的尺寸
inline const Size& getTileSize() const { return _tileSize; };
/** Set the tiles's size property measured in pixels.
*
* @param tileSize The tiles's size property measured in pixels.
*/
/// 设置瓦片的尺寸
inline void setTileSize(const Size& tileSize) { _tileSize = tileSize; };
/** Get map orientation.
*
* @return The map orientation.
*/
/// 得到地图的方向
inline int getMapOrientation() const { return _mapOrientation; };
/** Set map orientation.
*
* @param mapOrientation The map orientation.
*/
/// 设置地图的方向
inline void setMapOrientation(int mapOrientation) { _mapOrientation = mapOrientation; };
/** Get object groups.
*
* @return Object groups.
*/
/// 得到对象组
inline const Vector<TMXObjectGroup*>& getObjectGroups() const { return _objectGroups; };
inline Vector<TMXObjectGroup*>& getObjectGroups() { return _objectGroups; };
/** Set object groups.
*
* @param groups An object groups.
*/
/// 设置对象组
inline void setObjectGroups(const Vector<TMXObjectGroup*>& groups) {
_objectGroups = groups;
};
/** Get properties.
*
* @return Properties.
*/
/// 得到所有的属性
inline const ValueMap& getProperties() const { return _properties; };
/** Set properties.
*
* @param properties An ValueMap Properties.
*/
/// 设置属性
inline void setProperties(const ValueMap& properties) {
_properties = properties;
};
/// 得到描述
virtual std::string getDescription() const override;
protected:
/**
* @js ctor
*/
TMXTiledMap();
/**
* @js NA
* @lua NA
*/
virtual ~TMXTiledMap();
/** initializes a TMX Tiled Map with a TMX file */
/// 初始化
bool initWithTMXFile(const std::string& tmxFile);
/** initializes a TMX Tiled Map with a TMX formatted XML string and a path to TMX resources */
/// 初始化
bool initWithXML(const std::string& tmxString, const std::string& resourcePath);
/// 解析tmx
TMXLayer * parseLayer(TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo);
TMXTilesetInfo * tilesetForLayer(TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo);
void buildWithMapInfo(TMXMapInfo* mapInfo);
/** the map's size property measured in tiles */
Size _mapSize;
/** the tiles's size property measured in pixels */
Size _tileSize;
/** map orientation */
int _mapOrientation;
/** object groups */
Vector<TMXObjectGroup*> _objectGroups;
/** properties */
ValueMap _properties;
//! tile properties
ValueMapIntKey _tileProperties;
private:
CC_DISALLOW_COPY_AND_ASSIGN(TMXTiledMap);
};