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
CCTMXTiledMap Class Reference

#import <CCTMXTiledMap.h>

+ Inheritance diagram for CCTMXTiledMap:
+ Collaboration diagram for CCTMXTiledMap:

List of all members.

Public Member Functions

(id) - initWithTMXFile:
(id) - initWithXML:resourcePath:
(CCTMXLayer *) - layerNamed:
(CCTMXObjectGroup *) - objectGroupNamed:
(id) - propertyNamed:
(NSDictionary *) - propertiesForGID:

Static Public Member Functions

(id) + tiledMapWithTMXFile:
(id) + tiledMapWithXML:resourcePath:

Protected Attributes

CGSize _mapSize
CGSize _tileSize
int _mapOrientation
NSMutableArray * _objectGroups
NSMutableDictionary * _properties
NSMutableDictionary * _tileProperties

Properties

CGSize mapSize
CGSize tileSize
int mapOrientation
NSMutableArray * objectGroups
NSMutableDictionary * properties

Detailed Description

CCTMXTiledMap knows how to parse and render a TMX map.

It adds support for the TMX tiled map format used by http://www.mapeditor.org It supports isometric, hexagonal and orthogonal tiles. It also supports object groups, objects, and properties.

Features:

  • Each tile will be treated as an CCSprite
  • The sprites are created on demand. They will be created only when you call "[layer tileAt:]"
  • Each tile can be rotated / moved / scaled / tinted / "opacitied", since each tile is a CCSprite
  • Tiles can be added/removed in runtime
  • The z-order of the tiles can be modified in runtime
  • Each tile has an anchorPoint of (0,0)
  • The anchorPoint of the TMXTileMap is (0,0)
  • The TMX layers will be added as a child
  • The TMX layers will be aliased by default
  • The tileset image will be loaded using the CCTextureCache
  • Each tile will have a unique tag
  • Each tile will have a unique z value. top-left: z=1, bottom-right: z=max z
  • Each object group will be treated as an NSMutableArray
  • Object class which will contain all the properties in a dictionary
  • Properties can be assigned to the Map, Layer, Object Group, and Object

Limitations:

  • It only supports one tileset per layer.
  • Embedded images are not supported
  • It only supports the XML format (the JSON format is not supported)

Technical description: Each layer is created using an CCTMXLayer (subclass of CCSpriteBatchNode). If you have 5 layers, then 5 CCTMXLayer will be created, unless the layer visibility is off. In that case, the layer won't be created at all. You can obtain the layers (CCTMXLayer objects) at runtime by:

  • [map getChildByTag: tax_number]; // 0=1st layer, 1=2nd layer, 2=3rd layer, etc...
  • [map layerNamed: name_of_the_layer];

Each object group is created using a CCTMXObjectGroup which is a subclass of NSMutableArray. You can obtain the object groups at runtime by:

  • [map objectGroupNamed: name_of_the_object_group];

Each object is a CCTMXObject.

Each property is stored as a key-value pair in an NSMutableDictionary. You can obtain the properties at runtime by:

 [map propertyNamed: name_of_the_property];
 [layer propertyNamed: name_of_the_property];
 [objectGroup propertyNamed: name_of_the_property];
 [object propertyNamed: name_of_the_property];
Since:
v0.8.1

Member Function Documentation

- (id) initWithTMXFile: (NSString *)  tmxFile

initializes a TMX Tiled Map with a TMX file

- (id) initWithXML: (NSString *)  tmxString
resourcePath: (NSString *)  resourcePath 

initializes a TMX Tiled Map with a TMX formatted XML string and a path to TMX resources

- (CCTMXLayer*) layerNamed: (NSString *)  layerName

return the TMXLayer for the specific layer

- (CCTMXObjectGroup*) objectGroupNamed: (NSString *)  groupName

return the TMXObjectGroup for the specific group

- (NSDictionary*) propertiesForGID: (unsigned int)  GID

return properties dictionary for tile GID

- (id) propertyNamed: (NSString *)  propertyName

return the value for the specific property name

+ (id) tiledMapWithTMXFile: (NSString *)  tmxFile

creates a TMX Tiled Map with a TMX file.

+ (id) tiledMapWithXML: (NSString *)  tmxString
resourcePath: (NSString *)  resourcePath 

initializes a TMX Tiled Map with a TMX formatted XML string and a path to TMX resources


Property Documentation

- (int) mapOrientation [read, assign]

map orientation

- (CGSize) mapSize [read, assign]

the map's size property measured in tiles

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

object groups

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

properties

- (CGSize) tileSize [read, assign]

the tiles's size property measured in pixels


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