2011-03-19 10:59:01 +08:00
|
|
|
/****************************************************************************
|
2012-09-24 21:22:20 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2011-03-19 10:59:01 +08:00
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
2011-07-04 14:11:43 +08:00
|
|
|
Copyright (c) 2011 Zynga 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
|
|
|
|
|
|
|
|
2012-06-19 13:50:11 +08:00
|
|
|
#include "base_nodes/CCAtlasNode.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
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
struct sImageTGA;
|
2013-06-20 14:13:12 +08:00
|
|
|
class Dictionary;
|
2012-06-20 18:09:11 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup tilemap_parallax_nodes
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
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
|
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
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
/** TileMap info */
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_PROPERTY(struct sImageTGA*, _TGAInfo, TGAInfo);
|
2012-04-18 18:43:45 +08:00
|
|
|
public:
|
2013-06-20 14:13:12 +08:00
|
|
|
TileMapAtlas();
|
|
|
|
virtual ~TileMapAtlas();
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** creates a TileMap with a tile file (atlas) with a map file and the width and height of each tile in points.
|
2012-06-14 15:13:16 +08:00
|
|
|
The tile file will be loaded using the TextureMgr.
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
static TileMapAtlas * create(const char *tile, const char *mapFile, int tileWidth, int tileHeight);
|
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.
|
|
|
|
*/
|
|
|
|
bool initWithTileFile(const char *tile, const char *mapFile, int tileWidth, int tileHeight);
|
|
|
|
/** returns a tile from position x,y.
|
|
|
|
For the moment only channel R is used
|
|
|
|
*/
|
2013-07-05 16:49:22 +08:00
|
|
|
Color3B tileAt(const Point& position);
|
2012-04-19 14:35:52 +08:00
|
|
|
/** sets a tile at position x,y.
|
|
|
|
For the moment only channel R is used
|
|
|
|
*/
|
2013-07-05 16:49:22 +08:00
|
|
|
void setTile(const Color3B& tile, const Point& position);
|
2012-04-19 14:35:52 +08:00
|
|
|
/** dealloc the map from memory */
|
|
|
|
void releaseMap();
|
2012-04-18 18:43:45 +08:00
|
|
|
private:
|
2012-04-19 14:35:52 +08:00
|
|
|
void loadTGAfile(const char *file);
|
|
|
|
void calculateItemsToRender();
|
2013-07-05 16:49:22 +08:00
|
|
|
void updateAtlasValueAt(const Point& pos, const Color3B& value, unsigned int index);
|
2012-04-19 14:35:52 +08:00
|
|
|
void updateAtlasValues();
|
2012-04-18 18:43:45 +08:00
|
|
|
|
|
|
|
protected:
|
2012-09-17 15:02:24 +08:00
|
|
|
//! x,y to atlas dictionary
|
2013-06-20 14:13:12 +08:00
|
|
|
Dictionary* _posToAtlasIndex;
|
2012-04-19 14:35:52 +08:00
|
|
|
//! numbers of tiles to render
|
2013-06-15 14:03:30 +08:00
|
|
|
int _itemsToRender;
|
2012-04-18 18:43:45 +08:00
|
|
|
};
|
2010-08-30 15:23:07 +08:00
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
// end of tilemap_parallax_nodes group
|
|
|
|
/// @}
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_END
|
2011-03-19 10:59:01 +08:00
|
|
|
|
|
|
|
#endif //__CCTILE_MAP_ATLAS__
|
|
|
|
|