博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CCTMXXMLParser
阅读量:4979 次
发布时间:2019-06-12

本文共 5486 字,大约阅读时间需要 18 分钟。

#ifndef __CC_TM_XML_PARSER__

#define __CC_TM_XML_PARSER__

#include "cocoa/CCArray.h"

#include "cocoa/CCDictionary.h"

#include "cocoa/CCGeometry.h"

#include "platform/CCSAXParser.h"

#include <string>

NS_CC_BEGIN

class CCTMXObjectGroup;

/** @file

* Internal TMX parser

*

* IMPORTANT: These classed should not be documented using doxygen strings

* since the user should not use them.

*

*/

/**

 * @addtogroup tilemap_parallax_nodes

 * @{

 */

enum {

    TMXLayerAttribNone = 1 << 0,

    TMXLayerAttribBase64 = 1 << 1,

    TMXLayerAttribGzip = 1 << 2,

    TMXLayerAttribZlib = 1 << 3,

};

enum {

    TMXPropertyNone,

    TMXPropertyMap,

    TMXPropertyLayer,

    TMXPropertyObjectGroup,

    TMXPropertyObject,

    TMXPropertyTile

};

typedef enum ccTMXTileFlags_ {

    kCCTMXTileHorizontalFlag        = 0x80000000,

    kCCTMXTileVerticalFlag            = 0x40000000,

    kCCTMXTileDiagonalFlag            = 0x20000000,

    kCCFlipedAll                    = (kCCTMXTileHorizontalFlag|kCCTMXTileVerticalFlag|kCCTMXTileDiagonalFlag),

    kCCFlippedMask                    = ~(kCCFlipedAll)

} ccTMXTileFlags;

// Bits on the far end of the 32-bit global tile ID (GID's) are used for tile flags

/** @brief CCTMXLayerInfo contains the information about the layers like:

- Layer name

- Layer size

- Layer opacity at creation time (it can be modified at runtime)

- Whether the layer is visible (if it's not visible, then the CocosNode won't be created)

This information is obtained from the TMX file.

*/

class CC_DLL CCTMXLayerInfo : public CCObject

{

    CC_PROPERTY(CCDictionary*, m_pProperties, Properties);

public:

    std::string         m_sName;

    CCSize              m_tLayerSize;

    unsigned int        *m_pTiles;

    bool                m_bVisible;

    unsigned char       m_cOpacity;

    bool                m_bOwnTiles;

    unsigned int        m_uMinGID;

    unsigned int        m_uMaxGID;

    CCPoint             m_tOffset;

public:

    CCTMXLayerInfo();

    virtual ~CCTMXLayerInfo();

};

/** @brief CCTMXTilesetInfo contains the information about the tilesets like:

- Tileset name

- Tileset spacing

- Tileset margin

- size of the tiles

- Image used for the tiles

- Image size

This information is obtained from the TMX file. 

*/

class CC_DLL CCTMXTilesetInfo : public CCObject

{

public:

    std::string     m_sName;

    unsigned int    m_uFirstGid;

    CCSize          m_tTileSize;

    unsigned int    m_uSpacing;

    unsigned int    m_uMargin;

    //! filename containing the tiles (should be spritesheet / texture atlas)

    std::string     m_sSourceImage;

    //! size in pixels of the image

    CCSize          m_tImageSize;

public:

    CCTMXTilesetInfo();

    virtual ~CCTMXTilesetInfo();

    CCRect rectForGID(unsigned int gid);

};

/** @brief CCTMXMapInfo contains the information about the map like:

- Map orientation (hexagonal, isometric or orthogonal)

- Tile size

- Map size

And it also contains:

- Layers (an array of TMXLayerInfo objects)

- Tilesets (an array of TMXTilesetInfo objects)

- ObjectGroups (an array of TMXObjectGroupInfo objects)

This information is obtained from the TMX file.

*/

class CC_DLL CCTMXMapInfo : public CCObject, public CCSAXDelegator

{    

public:    

    /// map orientation

    CC_SYNTHESIZE(int,    m_nOrientation, Orientation);

    /// map width & height

    CC_SYNTHESIZE_PASS_BY_REF(CCSize, m_tMapSize, MapSize);

    /// tiles width & height

    CC_SYNTHESIZE_PASS_BY_REF(CCSize, m_tTileSize, TileSize);

    /// Layers

    CC_PROPERTY(CCArray*, m_pLayers, Layers);

    /// tilesets

    CC_PROPERTY(CCArray*, m_pTilesets, Tilesets);

    /// ObjectGroups

    CC_PROPERTY(CCArray*, m_pObjectGroups, ObjectGroups);

    /// parent element

    CC_SYNTHESIZE(int, m_nParentElement, ParentElement);

    /// parent GID

    CC_SYNTHESIZE(unsigned int, m_uParentGID, ParentGID);

    /// layer attribs

    CC_SYNTHESIZE(int, m_nLayerAttribs, LayerAttribs);

    /// is storing characters?

    CC_SYNTHESIZE(bool, m_bStoringCharacters, StoringCharacters);

    /// properties

    CC_PROPERTY(CCDictionary*, m_pProperties, Properties);

public:    

    CCTMXMapInfo();

    virtual ~CCTMXMapInfo();

    /** creates a TMX Format with a tmx file */

    static CCTMXMapInfo * formatWithTMXFile(const char *tmxFile);

    /** creates a TMX Format with an XML string and a TMX resource path */

    static CCTMXMapInfo * formatWithXML(const char* tmxString, const char* resourcePath);

    /** initializes a TMX format with a  tmx file */

    bool initWithTMXFile(const char *tmxFile);

    /** initializes a TMX format with an XML string and a TMX resource path */

    bool initWithXML(const char* tmxString, const char* resourcePath);

    /** initializes parsing of an XML file, either a tmx (Map) file or tsx (Tileset) file */

    bool parseXMLFile(const char *xmlFilename);

    /* initializes parsing of an XML string, either a tmx (Map) string or tsx (Tileset) string */

    bool parseXMLString(const char *xmlString);

    CCDictionary* getTileProperties();

    void setTileProperties(CCDictionary* tileProperties);

    // implement pure virtual methods of CCSAXDelegator

    void startElement(void *ctx, const char *name, const char **atts);

    void endElement(void *ctx, const char *name);

    void textHandler(void *ctx, const char *ch, int len);

    

    inline const char* getCurrentString(){ return m_sCurrentString.c_str(); }

    inline void setCurrentString(const char *currentString){ m_sCurrentString = currentString; }

    inline const char* getTMXFileName(){ return m_sTMXFileName.c_str(); }

    inline void setTMXFileName(const char *fileName){ m_sTMXFileName = fileName; }

private:

    void internalInit(const char* tmxFileName, const char* resourcePath);

protected:

    //! tmx filename

    std::string m_sTMXFileName;

    // tmx resource path

    std::string m_sResources;

    //! current string

    std::string m_sCurrentString;

    //! tile properties

    CCDictionary* m_pTileProperties;

    unsigned int m_uCurrentFirstGID;

};

// end of tilemap_parallax_nodes group

/// @}

NS_CC_END

#endif

转载于:https://www.cnblogs.com/sssssnian/p/3748616.html

你可能感兴趣的文章
Linux环境下SolrCloud集群环境搭建关键步骤
查看>>
MongoDB的简单使用
查看>>
【noip2004】虫食算——剪枝DFS
查看>>
java小技巧
查看>>
POJ 3204 Ikki's Story I - Road Reconstruction
查看>>
SQL中Group By的使用
查看>>
两个表格中数据不用是一一对应关系--来筛选不同数据,或者相同数据
查看>>
js05-DOM对象二
查看>>
mariadb BINLOG_FORMAT = STATEMENT 异常
查看>>
Java回顾之多线程
查看>>
机电行业如何进行信息化建设
查看>>
2018 Multi-University Training Contest 10 - Count
查看>>
HDU6203 ping ping ping
查看>>
Fireworks基本使用
查看>>
Java基础常见英语词汇
查看>>
nginx启动、关闭命令、重启nginx报错open() "/var/run/nginx/nginx.pid" failed
查看>>
BZOJ 3097 Hash Killer I
查看>>
UINavigationController的视图层理关系
查看>>
html阴影效果怎么做,css 内阴影怎么做
查看>>
BZOJ1026: [SCOI2009]windy数
查看>>