CCTMXTiledMap

#ifndef __CCTMX_TILE_MAP_H__

#define __CCTMX_TILE_MAP_H__


#include "base_nodes/CCNode.h"

#include "CCTMXObjectGroup.h"


NS_CC_BEGIN


class CCTMXObjectGroup;

class CCTMXLayer;

class CCTMXLayerInfo;

class CCTMXTilesetInfo;

class CCTMXMapInfo;


/**

 * @addtogroup tilemap_parallax_nodes

 * @{

 */


/** Possible orientations of the TMX map */

enum

{

    /** Orthogonal orientation */

    CCTMXOrientationOrtho,


    /** Hexagonal orientation */

    CCTMXOrientationHex,


    /** Isometric orientation */

    CCTMXOrientationIso,

};


/** @brief CCTMXTiledMap knows how to parse and render a TMX map.


It adds support for the TMX tiled map format used byhttp://www.mapeditor.org

It supports isometric, hexagonal and orthogonal tiles.

It also supports object groups, objects, and properties.


Features:

- Each tile will be treated as an CCSprite

- The sprites are created on demand. They will be created only when you call "layer->tileAt(position)"

- Each tile can be rotated / moved / scaled / tinted / "opaqued", since each tile is a CCSprite

- Tiles can be added/removed in runtime

- The z-order of the tiles can be modified in runtime

- Each tile has an anchorPoint of (0,0)

- The anchorPoint of the TMXTileMap is (0,0)

- The TMX layers will be added as a child

- The TMX layers will be aliased by default

- The tileset image will be loaded using the CCTextureCache

- Each tile will have a unique tag

- Each tile will have a unique z value. top-left: z=1, bottom-right: z=max z

- Each object group will be treated as an CCMutableArray

- Object class which will contain all the properties in a dictionary

- Properties can be assigned to the Map, Layer, Object Group, and Object


Limitations:

- It only supports one tileset per layer.

- Embedded images are not supported

- It only supports the XML format (the JSON format is not supported)


Technical description:

Each layer is created using an CCTMXLayer (subclass of CCSpriteBatchNode). If you have 5 layers, then 5 CCTMXLayer will be created,

unless the layer visibility is off. In that case, the layer won't be created at all.

You can obtain the layers (CCTMXLayer objects) at runtime by:

- map->getChildByTag(tag_number);  // 0=1st layer, 1=2nd layer, 2=3rd layer, etc...

- map->layerNamed(name_of_the_layer);


Each object group is created using a CCTMXObjectGroup which is a subclass of CCMutableArray.

You can obtain the object groups at runtime by:

- map->objectGroupNamed(name_of_the_object_group);


Each object is a CCTMXObject.


Each property is stored as a key-value pair in an CCMutableDictionary.

You can obtain the properties at runtime by:


map->propertyNamed(name_of_the_property);

layer->propertyNamed(name_of_the_property);

objectGroup->propertyNamed(name_of_the_property);

object->propertyNamed(name_of_the_property);


@since v0.8.1

*/

class CC_DLL CCTMXTiledMap : public CCNode

{

    /** the map's size property measured in tiles */

    CC_SYNTHESIZE_PASS_BY_REF(CCSize, m_tMapSize, MapSize);

    /** the tiles's size property measured in pixels */

    CC_SYNTHESIZE_PASS_BY_REF(CCSize, m_tTileSize, TileSize);

    /** map orientation */

    CC_SYNTHESIZE(int, m_nMapOrientation, MapOrientation);

    /** object groups */

    CC_PROPERTY(CCArray*, m_pObjectGroups, ObjectGroups);

    /** properties */

    CC_PROPERTY(CCDictionary*, m_pProperties, Properties);

public:

    CCTMXTiledMap();

    virtual ~CCTMXTiledMap();


    /** creates a TMX Tiled Map with a TMX file.*/

    static CCTMXTiledMap* create(const char *tmxFile);


    /** initializes a TMX Tiled Map with a TMX formatted XML string and a path to TMX resources */

    static CCTMXTiledMap* createWithXML(const char* tmxString, const char* resourcePath);


    /** initializes a TMX Tiled Map with a TMX file */

    bool initWithTMXFile(const char *tmxFile);


    /** initializes a TMX Tiled Map with a TMX formatted XML string and a path to TMX resources */

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


    /** return the TMXLayer for the specific layer */

    CCTMXLayer* layerNamed(const char *layerName);


    /** return the TMXObjectGroup for the specific group */

    CCTMXObjectGroup* objectGroupNamed(const char *groupName);


    /** return the value for the specific property name */

    CCString *propertyNamed(const char *propertyName);


    /** return properties dictionary for tile GID */

    CCDictionary* propertiesForGID(int GID);


private:

    CCTMXLayer * parseLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo);

    CCTMXTilesetInfo * tilesetForLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo);

    void buildWithMapInfo(CCTMXMapInfo* mapInfo);

protected:

    //! tile properties

    CCDictionary* m_pTileProperties;


};


// end of tilemap_parallax_nodes group

/// @}


NS_CC_END


#endif //__CCTMX_TILE_MAP_H__



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值