Class CCTMXLayer

#include <Geode/cocos/tilemap_parallax_nodes/CCTMXLayer.h>
classCCTMXLayer:publiccocos2d::CCSpriteBatchNode{ ... }

Since 1.1

CCTMXLayer represents the TMX layer. It is a subclass of CCSpriteBatchNode. By default the tiles are rendered using a CCTextureAtlas. If you modify a tile on runtime, then, that tile will become a CCSprite, otherwise no CCSprite objects are created. The benefits of using CCSprite objects as tiles are:

  • tiles (CCSprite) can be rotated/scaled/moved with a nice API If the layer contains a property named “cc_vertexz” with an integer (in can be positive or negative), then all the tiles belonging to the layer will use that value as their OpenGL vertex Z for depth. On the other hand, if the “cc_vertexz” property has the “automatic” value, then the tiles will use an automatic vertex Z value. Also before drawing the tiles, GL_ALPHA_TEST will be enabled, and disabled after drawing them. The used alpha func will be: glAlphaFunc( GL_GREATER, value ) “value” by default is 0, but you can change it from Tiled by adding the “cc_alpha_func” property to the layer. The value 0 should work for most cases, but if you have tiles that are semi-transparent, then you might want to use a different value, like 0.5. For further information, please see the programming guide: http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:tiled_maps
Examples0
Public static methods1
staticcocos2d::CCTMXLayer*create(,,)

creates a CCTMXLayer with an tileset info, a layer info and a map info

Public member functions27
virtualcocos2d::CCSizeconst&getLayerSize()const
No description provided
virtualvoidsetLayerSize()
No description provided
virtualcocos2d::CCSizeconst&getMapTileSize()const
No description provided
virtualvoidsetMapTileSize()
No description provided
virtualuint*getTiles()const
No description provided
virtualvoidsetTiles()
No description provided
virtualcocos2d::CCTMXTilesetInfo*getTileSet()
No description provided
virtualvoidsetTileSet()
No description provided
virtualuintgetLayerOrientation()const
No description provided
virtualvoidsetLayerOrientation(
uintvar
)
No description provided
virtualcocos2d::CCDictionary*getProperties()
No description provided
virtualvoidsetProperties()
No description provided
boolinitWithTilesetInfo(,,)

initializes a CCTMXLayer with a tileset info, a layer info and a map info

voidreleaseMap()

dealloc the map that contains the tile position from memory. Unless you want to know at runtime the tiles positions, you can safely call this method. If you are going to call layer->tileGIDAt() then, don’t release the map

cocos2d::CCSprite*tileAt()

returns the tile (CCSprite) at a given a tile coordinate. The returned CCSprite will be already added to the CCTMXLayer. Don’t add it again. The CCSprite can be treated like any other CCSprite: rotated, scaled, translated, opacity, color, etc. You can remove either by calling:

  • layer->removeChild(sprite, cleanup);
  • or layer->removeTileAt(ccp(x,y));
uinttileGIDAt()

returns the tile gid at a given tile coordinate. if it returns 0, it means that the tile is empty. This method requires the the tile map has not been previously released (eg. don’t call layer->releaseMap())

uinttileGIDAt(,)

returns the tile gid at a given tile coordinate. It also returns the tile flags. This method requires the the tile map has not been previously released (eg. don’t call [layer releaseMap])

voidsetTileGID(
uintgid
,)

sets the tile gid (gid = tile global id) at a given tile coordinate. The Tile GID can be obtained by using the method “tileGIDAt” or by using the TMX editor -> Tileset Mgr +1. If a tile is already placed at that position, then it will be removed.

voidsetTileGID(
uintgid
,,)

sets the tile gid (gid = tile global id) at a given tile coordinate. The Tile GID can be obtained by using the method “tileGIDAt” or by using the TMX editor -> Tileset Mgr +1. If a tile is already placed at that position, then it will be removed. Use withFlags if the tile flags need to be changed as well

voidremoveTileAt()

removes a tile at given tile coordinate

cocos2d::CCPointpositionAt()

returns the position in points of a given tile coordinate

cocos2d::CCString*propertyNamed(
charconst*propertyName
)

return the value for the specific property name

voidsetupTiles()

Creates the tiles

virtualvoidaddChild(,
intzOrder
,
inttag
)

CCTMXLayer doesn’t support adding a CCSprite manually.

⚠️ addchild(z, tag); is not supported on CCTMXLayer. Instead of setTileGID.

virtualvoidremoveChild(,
boolcleanup
)

super method

charconst*getLayerName()
No description provided
voidsetLayerName(
charconst*layerName
)
No description provided
Fields0
Protected member functions0
Protected fields15
cocos2d::CCSizem_tLayerSize
;
No description provided
cocos2d::CCSizem_tMapTileSize
;
No description provided
uint*m_pTiles
;
No description provided
;
No description provided
uintm_uLayerOrientation
;
No description provided
;
No description provided
gd::stringm_sLayerName
;

//! name of the layer

ucharm_cOpacity
;

//! TMX Layer supports opacity

uintm_uMinGID
;
No description provided
uintm_uMaxGID
;
No description provided
intm_nVertexZvalue
;

//! Only used when vertexZ is used

boolm_bUseAutomaticVertexZ
;
No description provided
cocos2d::CCSprite*m_pReusedTile
;

//! used for optimization

cocos2d::ccCArray*m_pAtlasIndexArray
;
No description provided
floatm_fContentScaleFactor
;
No description provided