cocos2d-iphone  2.1
Improved Cocos2D API Reference (iOS version) for www.kobold2d.com developers
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Defines
CCTMXLayer Class Reference

#import <CCTMXLayer.h>

+ Inheritance diagram for CCTMXLayer:
+ Collaboration diagram for CCTMXLayer:

List of all members.

Public Member Functions

(id) - initWithTilesetInfo:layerInfo:mapInfo:
(void) - releaseMap
(CCSprite *) - tileAt:
(uint32_t) - tileGIDAt:
(uint32_t) - tileGIDAt:withFlags:
(void) - setTileGID:at:
(void) - setTileGID:at:withFlags:
(void) - removeTileAt:
(CGPoint) - positionAt:
(id) - propertyNamed:
(void) - setupTiles
(void) - addChild:z:tag:

Static Public Member Functions

(id) + layerWithTilesetInfo:layerInfo:mapInfo:

Protected Attributes

CCTMXTilesetInfo_tileset
NSString * _layerName
CGSize _layerSize
CGSize _mapTileSize
uint32_t * _tiles
NSUInteger _layerOrientation
NSMutableArray * _properties
unsigned char _opacity
NSUInteger _minGID
NSUInteger _maxGID
NSInteger _vertexZvalue
BOOL _useAutomaticVertexZ
CCSprite_reusedTile
ccCArray_atlasIndexArray

Properties

NSString * layerName
CGSize layerSize
CGSize mapTileSize
uint32_t * tiles
CCTMXTilesetInfotileset
NSUInteger layerOrientation
NSMutableArray * properties

Detailed Description

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

Since:
v0.8.1

Tiles can have tile flags for additional properties. At the moment only flip horizontal and flip vertical are used. These bit flags are defined in CCTMXXMLParser.h.

Since:
1.1

Member Function Documentation

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

CCTMXLayer doesn't support adding a CCSprite manually.

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

Implements CCNode.

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

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

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

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

- (CGPoint) positionAt: (CGPoint)  tileCoordinate

returns the position in points of a given tile coordinate

- (id) propertyNamed: (NSString *)  propertyName

return the value for the specific property name

- (void) 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) removeTileAt: (CGPoint)  tileCoordinate

removes a tile at given tile coordinate

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

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 

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

- (void) setupTiles

Creates the tiles

- (CCSprite*) tileAt: (CGPoint)  tileCoordinate

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)];
- (uint32_t) tileGIDAt: (CGPoint)  tileCoordinate

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)  pos
withFlags: (ccTMXTileFlags *)  flags 

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


Property Documentation

- (NSString*) layerName [read, write, retain]

name of the layer

- (NSUInteger) layerOrientation [read, write, assign]

Layer orientation, which is the same as the map orientation

- (CGSize) layerSize [read, write, assign]

size of the layer in tiles

- (CGSize) mapTileSize [read, write, assign]

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

- (NSMutableArray*) properties [read, write, retain]

properties from the layer. They can be added using Tiled

- (uint32_t*) tiles [read, write, assign]

pointer to the map of tiles

- (CCTMXTilesetInfo*) tileset [read, write, retain]

Tileset information for the layer


The documentation for this class was generated from the following file: