Inherits from CCSpriteBatchNode : CCNode : NSObject
Declared in CCTMXLayer.h

Overview

CCTMXLayer represents the TMX layer.

It is a subclass of CCSpriteBatchNode. By default the tiles are rendered using a CCTextureAtlas. If you mofify 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

cocos2d v2.0 doesn’t support the cc_vertexz value. Whenever a the cc_vertexz property is found, it will raise an exception.

“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 differnt value, like 0.5.

For further information, please see the programming guide:

http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:tiled_maps

Tasks

  •   layerName

    name of the layer

    property
  •   layerSize

    size of the layer in tiles

    property
  •   mapTileSize

    size of the map’s tile (could be different from the tile’s size)

    property
  •   tiles

    pointer to the map of tiles

    property
  •   tileset

    Tileset information for the layer

    property
  •   layerOrientation

    Layer orientation, which is the same as the map orientation

    property
  •   properties

    properties from the layer. They can be added using Tiled

    property
  • + layerWithTilesetInfo:layerInfo:mapInfo:

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

  • – initWithTilesetInfo:layerInfo:mapInfo:

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

  • – releaseMap

    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

  • – 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:cleanup];
    - or [layer removeTileAt:ccp(x,y)];
    
  • – tileGIDAt:

    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])

  • – tileGIDAt:withFlags:

    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])

  • – setTileGID:at:

    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.

  • – setTileGID:at:withFlags:

    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.

  • – removeTileAt:

    removes a tile at given tile coordinate

  • – positionAt:

    returns the position in points of a given tile coordinate

  • – propertyNamed:

    return the value for the specific property name

  • – setupTiles

    Creates the tiles

  • – addChild:z:tag:

    CCTMXLayer doesn’t support adding a CCSprite manually.

Properties

layerName

name of the layer

@property (nonatomic, readwrite, retain) NSString *layerName

Declared In

CCTMXLayer.h

layerOrientation

Layer orientation, which is the same as the map orientation

@property (nonatomic, readwrite) NSUInteger layerOrientation

Declared In

CCTMXLayer.h

layerSize

size of the layer in tiles

@property (nonatomic, readwrite) CGSize layerSize

Declared In

CCTMXLayer.h

mapTileSize

size of the map’s tile (could be different from the tile’s size)

@property (nonatomic, readwrite) CGSize mapTileSize

Declared In

CCTMXLayer.h

properties

properties from the layer. They can be added using Tiled

@property (nonatomic, readwrite, retain) NSMutableArray *properties

Declared In

CCTMXLayer.h

tiles

pointer to the map of tiles

@property (nonatomic, readwrite) uint32_t *tiles

Declared In

CCTMXLayer.h

tileset

Tileset information for the layer

@property (nonatomic, readwrite, retain) CCTMXTilesetInfo *tileset

Declared In

CCTMXLayer.h

Class Methods

layerWithTilesetInfo:layerInfo:mapInfo:

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

+ (id)layerWithTilesetInfo:(CCTMXTilesetInfo *)tilesetInfo layerInfo:(CCTMXLayerInfo *)layerInfo mapInfo:(CCTMXMapInfo *)mapInfo

Declared In

CCTMXLayer.h

Instance Methods

addChild:z:tag:

CCTMXLayer doesn’t support adding a CCSprite manually.

- (void)addChild:(CCNode *)node z:(NSInteger)z tag:(NSInteger)tag

Discussion

Warning: addchild:z:tag: is not supported on CCTMXLayer. Instead of setTileGID:at:/tileAt:

Declared In

CCTMXLayer.h

initWithTilesetInfo:layerInfo:mapInfo:

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

- (id)initWithTilesetInfo:(CCTMXTilesetInfo *)tilesetInfo layerInfo:(CCTMXLayerInfo *)layerInfo mapInfo:(CCTMXMapInfo *)mapInfo

Declared In

CCTMXLayer.h

positionAt:

returns the position in points of a given tile coordinate

- (CGPoint)positionAt:(CGPoint)tileCoordinate

Declared In

CCTMXLayer.h

propertyNamed:

return the value for the specific property name

- (id)propertyNamed:(NSString *)propertyName

Declared In

CCTMXLayer.h

releaseMap

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

- (void)releaseMap

Declared In

CCTMXLayer.h

removeTileAt:

removes a tile at given tile coordinate

- (void)removeTileAt:(CGPoint)tileCoordinate

Declared In

CCTMXLayer.h

setTileGID:at:

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.

- (void)setTileGID:(uint32_t)gid at:(CGPoint)tileCoordinate

Declared In

CCTMXLayer.h

setTileGID:at:withFlags:

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.

- (void)setTileGID:(uint32_t)gid at:(CGPoint)pos withFlags:(ccTMXTileFlags)flags

Discussion

Use withFlags if the tile flags need to be changed as well

Declared In

CCTMXLayer.h

setupTiles

Creates the tiles

- (void)setupTiles

Declared In

CCTMXLayer.h

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:cleanup];
- or [layer removeTileAt:ccp(x,y)];
- (CCSprite *)tileAt:(CGPoint)tileCoordinate

Declared In

CCTMXLayer.h

tileGIDAt:

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])

- (uint32_t)tileGIDAt:(CGPoint)tileCoordinate

Declared In

CCTMXLayer.h

tileGIDAt:withFlags:

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])

- (uint32_t)tileGIDAt:(CGPoint)pos withFlags:(ccTMXTileFlags *)flags

Declared In

CCTMXLayer.h