2011-03-19 10:59:01 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2011-07-04 14:11:43 +08:00
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2017-02-14 14:36:57 +08:00
|
|
|
Copyright (c) 2013-2017 Chukong Technologies Inc.
|
2011-03-19 10:59:01 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef __CCTILE_MAP_ATLAS__
|
|
|
|
#define __CCTILE_MAP_ATLAS__
|
2012-06-11 14:44:32 +08:00
|
|
|
|
2014-08-28 17:03:29 +08:00
|
|
|
#include "2d/CCAtlasNode.h"
|
2014-04-27 01:35:57 +08:00
|
|
|
#include "base/CCValue.h"
|
2011-03-19 10:59:01 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_BEGIN
|
2010-08-30 15:23:07 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/// @cond DO_NOT_SHOW
|
2012-06-20 18:09:11 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
struct sImageTGA;
|
2012-06-20 18:09:11 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** @brief TileMapAtlas is a subclass of AtlasNode.
|
2010-08-30 15:23:07 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
It knows how to render a map based of tiles.
|
|
|
|
The tiles must be in a .PNG format while the map must be a .TGA file.
|
2010-08-30 15:23:07 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
For more information regarding the format, please see this post:
|
|
|
|
http://www.cocos2d-iphone.org/archives/27
|
2010-08-30 15:23:07 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
All features from AtlasNode are valid in TileMapAtlas
|
2012-04-18 18:43:45 +08:00
|
|
|
|
|
|
|
IMPORTANT:
|
|
|
|
This class is deprecated. It is maintained for compatibility reasons only.
|
|
|
|
You SHOULD not use this class.
|
2013-06-20 14:13:12 +08:00
|
|
|
Instead, use the newer TMX file format: TMXTiledMap
|
2015-03-28 14:28:16 +08:00
|
|
|
@js NA
|
2012-04-18 18:43:45 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL TileMapAtlas : public AtlasNode
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-07-19 14:57:54 +08:00
|
|
|
/** creates a TileMap with a tile file (atlas) with a map file and the width and height of each tile in points.
|
|
|
|
The tile file will be loaded using the TextureMgr.
|
|
|
|
*/
|
2013-11-16 08:37:57 +08:00
|
|
|
static TileMapAtlas * create(const std::string& tile, const std::string& mapFile, int tileWidth, int tileHeight);
|
2013-09-13 16:46:31 +08:00
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
TileMapAtlas();
|
2013-09-13 13:52:42 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
virtual ~TileMapAtlas();
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** initializes a TileMap with a tile file (atlas) with a map file and the width and height of each tile in points.
|
2012-04-19 14:35:52 +08:00
|
|
|
The file will be loaded using the TextureMgr.
|
|
|
|
*/
|
2013-11-16 08:37:57 +08:00
|
|
|
bool initWithTileFile(const std::string& tile, const std::string& mapFile, int tileWidth, int tileHeight);
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Returns a tile from position x,y.
|
|
|
|
*For the moment only channel R is used
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Color3B getTileAt(const Vec2& position) const;
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Returns a tile from position x,y.
|
|
|
|
*For the moment only channel R is used
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE Color3B tileAt(const Vec2& position) const { return getTileAt(position); };
|
2012-04-19 14:35:52 +08:00
|
|
|
/** sets a tile at position x,y.
|
|
|
|
For the moment only channel R is used
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void setTile(const Color3B& tile, const Vec2& position);
|
2012-04-19 14:35:52 +08:00
|
|
|
/** dealloc the map from memory */
|
|
|
|
void releaseMap();
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Query TGA image info.
|
|
|
|
*@return The TGA image info.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
struct sImageTGA* getTGAInfo() const { return _TGAInfo; }
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the TGA image info for TileMapAtlas
|
|
|
|
*@param TGAInfo The TGA info in sImageTGA.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setTGAInfo(struct sImageTGA* TGAInfo) { _TGAInfo = TGAInfo; }
|
2013-11-16 08:37:57 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void loadTGAfile(const std::string& file);
|
2012-04-19 14:35:52 +08:00
|
|
|
void calculateItemsToRender();
|
2014-05-15 01:07:09 +08:00
|
|
|
void updateAtlasValueAt(const Vec2& pos, const Color3B& value, int index);
|
2012-04-19 14:35:52 +08:00
|
|
|
void updateAtlasValues();
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2013-11-16 08:37:57 +08:00
|
|
|
|
2012-09-17 15:02:24 +08:00
|
|
|
//! x,y to atlas dictionary
|
2013-12-11 14:39:21 +08:00
|
|
|
ValueMap _posToAtlasIndex;
|
2012-04-19 14:35:52 +08:00
|
|
|
//! numbers of tiles to render
|
2013-06-15 14:03:30 +08:00
|
|
|
int _itemsToRender;
|
2013-07-19 14:57:54 +08:00
|
|
|
/** TileMap info */
|
2013-07-23 18:26:26 +08:00
|
|
|
struct sImageTGA* _TGAInfo;
|
2012-04-18 18:43:45 +08:00
|
|
|
};
|
2010-08-30 15:23:07 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/// @endcond
|
2012-06-20 18:09:11 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_END
|
2011-03-19 10:59:01 +08:00
|
|
|
|
|
|
|
#endif //__CCTILE_MAP_ATLAS__
|
|
|
|
|