Class cc.TMXTiledMap

Class Summary
Constructor Attributes Constructor Name and Description
 

cc.TMXTiledMap knows how to parse and render a TMX map.

Method Summary

Class Detail

cc.TMXTiledMap()

cc.TMXTiledMap 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 cc.Sprite
- The sprites are created on demand. They will be created only when you call "layer.getTileAt(position)"
- Each tile can be rotated / moved / scaled / tinted / "opacitied", since each tile is a cc.Sprite
- 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 cc.TextureCache
- 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 cc.MutableArray
- 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.
- Embeded images are not supported
- It only supports the XML format (the JSON format is not supported)

Technical description:
Each layer is created using an cc.TMXLayer (subclass of cc.SpriteBatchNode). If you have 5 layers, then 5 cc.TMXLayer 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 (cc.TMXLayer objects) at runtime by:
- map.getChildByTag(tag_number); // 0=1st layer, 1=2nd layer, 2=3rd layer, etc...
- map.getLayer(name_of_the_layer);

Each object group is created using a cc.TMXObjectGroup which is a subclass of cc.MutableArray.
You can obtain the object groups at runtime by:
- map.getObjectGroup(name_of_the_object_group);

Each object is a cc.TMXObject.

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

map.getProperty(name_of_the_property);
layer.getProperty(name_of_the_property);
objectGroup.getProperty(name_of_the_property);
object.getProperty(name_of_the_property);

Method Detail

  • <static> {cc.TMXTiledMap|undefined} cc.TMXTiledMap.create(tmxFile, resourcePath)
    Creates a TMX Tiled Map with a TMX file. Implementation cc.TMXTiledMap
    //example
    var map = cc.TMXTiledMap.create("hello.tmx");
    Parameters:
    {String} tmxFile
    {String} resourcePath
    Returns:
    {cc.TMXTiledMap|undefined}
  • <static> {cc.TMXTiledMap|undefined} cc.TMXTiledMap.createWithXML(tmxString, resourcePath)
    initializes a TMX Tiled Map with a TMX formatted XML string and a path to TMX resources
    Parameters:
    {String} tmxString
    {String} resourcePath
    Returns:
    {cc.TMXTiledMap|undefined}
  • {cc.TMXLayer} getLayer(layerName)
    return the TMXLayer for the specific layer
    Parameters:
    {String} layerName
    Returns:
    {cc.TMXLayer}
  • {Number} getMapOrientation()
    map orientation
    Returns:
    {Number}
  • {cc.Size} getMapSize()
    Returns:
    {cc.Size}
  • {cc.TMXObjectGroup} getObjectGroup(groupName)
    Return the TMXObjectGroup for the secific group
    Parameters:
    {String} groupName
    Returns:
    {cc.TMXObjectGroup}
  • {Array} getObjectGroups()
    object groups
    Returns:
    {Array}
  • {object} getProperties()
    properties
    Returns:
    {object}
  • {String} getProperty(propertyName)
    Return the value for the specific property name
    Parameters:
    {String} propertyName
    Returns:
    {String}
  • {cc.Size} getTileSize()
    Returns:
    {cc.Size}
  • {Boolean} initWithTMXFile(tmxFile, resourcePath)
    //example
    var map = new cc.TMXTiledMap()
    map.initWithTMXFile("hello.tmx");
    Parameters:
    {String} tmxFile
    resourcePath
    Returns:
    {Boolean}
  • {object} propertiesForGID(GID)
    Return properties dictionary for tile GID
    Parameters:
    {Number} GID
    Returns:
    {object}
  • setMapOrientation(Var)
    Parameters:
    {Number} Var
  • setMapSize(Var)
    Parameters:
    {cc.Size} Var
  • setObjectGroups(Var)
    Parameters:
    {Array} Var
  • setProperties(Var)
    Parameters:
    {object} Var
  • setTileSize(Var)
    Parameters:
    {cc.Size} Var