Class cc.TMXLayer

Class Summary
Constructor Attributes Constructor Name and Description
 

cc.TMXLayer represents the TMX layer.

Method Summary

Class Detail

cc.TMXLayer()

cc.TMXLayer represents the TMX layer.

It is a subclass of cc.SpriteBatchNode. By default the tiles are rendered using a cc.TextureAtlas.
If you modify a tile on runtime, then, that tile will become a cc.Sprite, otherwise no cc.Sprite objects are created.
The benefits of using cc.Sprite objects as tiles are:
- tiles (cc.Sprite) 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.

Field Detail

{Number} layerHeight
- Height of the layer
{String} layerName
- Name of the layer
{Number} layerOrientation
- Layer orientation
{Number} layerWidth
- Width of the layer
{Array} properties
- Properties from the layer. They can be added using tilemap editors
{Number} tileHeight
- Height of a tile
{Array} tiles
- Tiles for layer
{cc.TMXTilesetInfo} tileset
- Tileset for layer
{Number} tileWidth
- Width of a tile

Method Detail

  • <static> {cc.TMXLayer|Null} cc.TMXLayer.create(tilesetInfo, layerInfo, mapInfo)
    Creates a cc.TMXLayer with an tile set info, a layer info and a map info
    Parameters:
    {cc.TMXTilesetInfo} tilesetInfo
    {cc.TMXLayerInfo} layerInfo
    {cc.TMXMapInfo} mapInfo
    Deprecated:
    since v3.0 please use new cc.TMXLayer(tilesetInfo, layerInfo, mapInfo) instead.
    Returns:
    {cc.TMXLayer|Null}
  • ctor(tilesetInfo, layerInfo, mapInfo)
    Creates a cc.TMXLayer with an tile set info, a layer info and a map info
    Constructor of cc.TMXLayer
    Parameters:
    {cc.TMXTilesetInfo} tilesetInfo
    {cc.TMXLayerInfo} layerInfo
    {cc.TMXMapInfo} mapInfo
  • {String} getLayerName()
    Gets the layer name
    Returns:
    {String}
  • {Number} getLayerOrientation()
    Layer orientation, which is the same as the map orientation
    Returns:
    {Number}
  • {cc.Size} getLayerSize()
    Gets layer size.
    Returns:
    {cc.Size}
  • {cc.Size} getMapTileSize()
    Size of the map's tile (could be different from the tile's size)
    Returns:
    {cc.Size}
  • {cc.Point} getPositionAt(pos, y)
    Returns the position in pixels of a given tile coordinate
    Parameters:
    {cc.Point|Number} pos
    position or x
    {Number} y Optional
    Returns:
    {cc.Point}
  • {Array} getProperties()
    properties from the layer. They can be added using Tiled
    Returns:
    {Array}
  • {*} getProperty(propertyName)
    Return the value for the specific property name
    Parameters:
    {String} propertyName
    Returns:
    {*}
  • {cc.Sprite} getTileAt(pos, y)

    Returns the tile (cc.Sprite) at a given a tile coordinate.
    The returned cc.Sprite will be already added to the cc.TMXLayer. Don't add it again.
    The cc.Sprite can be treated like any other cc.Sprite: rotated, scaled, translated, opacity, color, etc.
    You can remove either by calling:
    - layer.removeChild(sprite, cleanup);
    - or layer.removeTileAt(ccp(x,y));

    Parameters:
    {cc.Point|Number} pos
    or x
    {Number} y Optional
    Returns:
    {cc.Sprite}
  • {Number} getTileFlagsAt(pos, y)
    lipped tiles can be changed dynamically
    Parameters:
    {cc.Point|Number} pos
    or x
    {Number} y Optional
    Returns:
    {Number}
  • {Number} getTileGIDAt(pos, y)
    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())
    Parameters:
    {cc.Point|Number} pos
    or x
    {Number} y Optional
    Returns:
    {Number}
  • {Array} getTiles()
    Pointer to the map of tiles
    Returns:
    {Array}
  • {cc.TMXTilesetInfo} getTileset()
    Tile set information for the layer
    Returns:
    {cc.TMXTilesetInfo}
  • {Boolean} initWithTilesetInfo(tilesetInfo, layerInfo, mapInfo)
    Initializes a cc.TMXLayer with a tileset info, a layer info and a map info
    Parameters:
    {cc.TMXTilesetInfo} tilesetInfo
    {cc.TMXLayerInfo} layerInfo
    {cc.TMXMapInfo} mapInfo
    Returns:
    {Boolean}
  • 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.getTileGIDAt() then, don't release the map

  • removeTileAt(pos, y)
    Removes a tile at given tile coordinate
    Parameters:
    {cc.Point|Number} pos
    position or x
    {Number} y Optional
  • setLayerName(layerName)
    Set the layer name
    Parameters:
    {String} layerName
  • setLayerOrientation(Var)
    Layer orientation, which is the same as the map orientation
    Parameters:
    {Number} Var
  • setLayerSize(Var)
    Set layer size
    Parameters:
    {cc.Size} Var
  • setMapTileSize(Var)
    Set the map tile size.
    Parameters:
    {cc.Size} Var
  • setProperties(Var)
    properties from the layer. They can be added using Tiled
    Parameters:
    {Array} Var
  • setTileGID(gid, posOrX, flagsOrY, 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.

    Parameters:
    {Number} gid
    {cc.Point|Number} posOrX
    position or x
    {Number} flagsOrY
    flags or y
    {Number} flags Optional
  • setTiles(Var)
    Pointer to the map of tiles
    Parameters:
    {Array} Var
  • setTileset(Var)
    Tile set information for the layer
    Parameters:
    {cc.TMXTilesetInfo} Var