123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- #ifndef __CCTMX_LAYER_H__
- #define __CCTMX_LAYER_H__
- #include "2d/CCSpriteBatchNode.h"
- #include "2d/CCTMXXMLParser.h"
- #include "base/ccCArray.h"
- NS_CC_BEGIN
- class TMXMapInfo;
- class TMXLayerInfo;
- class TMXTilesetInfo;
- struct _ccCArray;
- class CC_DLL TMXLayer : public SpriteBatchNode
- {
- public:
-
- static TMXLayer * create(TMXTilesetInfo *tilesetInfo, TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo);
-
- TMXLayer();
-
- virtual ~TMXLayer();
-
- bool initWithTilesetInfo(TMXTilesetInfo *tilesetInfo, TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo);
-
- void releaseMap();
-
- Sprite* getTileAt(const Vec2& tileCoordinate);
-
- CC_DEPRECATED_ATTRIBUTE Sprite* tileAt(const Vec2& tileCoordinate) { return getTileAt(tileCoordinate); };
-
-
- uint32_t getTileGIDAt(const Vec2& tileCoordinate, TMXTileFlags* flags = nullptr);
-
- CC_DEPRECATED_ATTRIBUTE uint32_t tileGIDAt(const Vec2& tileCoordinate, TMXTileFlags* flags = nullptr){
- return getTileGIDAt(tileCoordinate, flags);
- }
-
- void setTileGID(uint32_t gid, const Vec2& tileCoordinate);
-
- void setTileGID(uint32_t gid, const Vec2& tileCoordinate, TMXTileFlags flags);
-
- void removeTileAt(const Vec2& tileCoordinate);
-
- Vec2 getPositionAt(const Vec2& tileCoordinate);
-
- CC_DEPRECATED_ATTRIBUTE Vec2 positionAt(const Vec2& tileCoordinate) { return getPositionAt(tileCoordinate); };
-
- Value getProperty(const std::string& propertyName) const;
-
- CC_DEPRECATED_ATTRIBUTE Value propertyNamed(const std::string& propertyName) const { return getProperty(propertyName); };
-
- void setupTiles();
-
-
- const std::string& getLayerName() { return _layerName; }
-
-
- void setLayerName(const std::string& layerName) { _layerName = layerName; }
-
- const Size& getLayerSize() const { return _layerSize; }
-
-
- void setLayerSize(const Size& size) { _layerSize = size; }
-
-
- const Size& getMapTileSize() const { return _mapTileSize; }
-
-
- void setMapTileSize(const Size& size) { _mapTileSize = size; }
-
-
- uint32_t* getTiles() const { return _tiles; };
-
-
- void setTiles(uint32_t* tiles) { _tiles = tiles; };
-
-
- TMXTilesetInfo* getTileSet() const { return _tileSet; }
-
-
- void setTileSet(TMXTilesetInfo* info) {
- CC_SAFE_RETAIN(info);
- CC_SAFE_RELEASE(_tileSet);
- _tileSet = info;
- }
-
-
- int getLayerOrientation() const { return _layerOrientation; }
-
-
- void setLayerOrientation(int orientation) { _layerOrientation = orientation; }
-
-
- const ValueMap& getProperties() const { return _properties; }
-
-
- ValueMap& getProperties() { return _properties; }
-
-
- void setProperties(const ValueMap& properties) {
- _properties = properties;
- }
-
-
-
-
- using SpriteBatchNode::addChild;
- virtual void addChild(Node * child, int zOrder, int tag) override;
-
- void removeChild(Node* child, bool cleanup) override;
-
- virtual std::string getDescription() const override;
- protected:
- Vec2 getPositionForIsoAt(const Vec2& pos);
- Vec2 getPositionForOrthoAt(const Vec2& pos);
- Vec2 getPositionForHexAt(const Vec2& pos);
- Vec2 getPositionForStaggeredAt(const Vec2& pos);
- Vec2 calculateLayerOffset(const Vec2& offset);
-
- Sprite* appendTileForGID(uint32_t gid, const Vec2& pos);
- Sprite* insertTileForGID(uint32_t gid, const Vec2& pos);
- Sprite* updateTileForGID(uint32_t gid, const Vec2& pos);
- intptr_t getZForPos(const Vec2& pos) const;
-
- void parseInternalProperties();
- void setupTileSprite(Sprite* sprite, const Vec2& pos, uint32_t gid);
- Sprite* reusedTileWithRect(const Rect& rect);
- int getVertexZForPos(const Vec2& pos);
-
- ssize_t atlasIndexForExistantZ(int z);
- ssize_t atlasIndexForNewZ(int z);
-
- std::string _layerName;
-
- unsigned char _opacity;
-
-
- int _vertexZvalue;
- bool _useAutomaticVertexZ;
-
- Sprite *_reusedTile;
- ccCArray *_atlasIndexArray;
-
-
- float _contentScaleFactor;
-
-
- Size _layerSize;
-
- Size _mapTileSize;
-
- uint32_t* _tiles;
-
- TMXTilesetInfo* _tileSet;
-
- int _layerOrientation;
-
- int _staggerAxis;
-
- int _staggerIndex;
-
- int _hexSideLength;
-
- ValueMap _properties;
- };
- NS_CC_END
- #endif
|