Class cc.TMXLayer
- Defined in: CCTMXLayer.js
- Extends cc.SpriteBatchNode
Constructor Attributes | Constructor Name and Description |
---|---|
cc.TMXLayer represents the TMX layer. |
Method Summary
Class Detail
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:
"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
Method Detail
-
addChild(child, zOrder, tag)cc.TMXLayer doesn't support adding a cc.Sprite manually.
- Parameters:
- {cc.Node} child
- {number} zOrder
- {number} tag
-
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
- Returns:
- {cc.TMXLayer|Null}
-
ctor()Constructor
-
{String} getLayerName()
- Returns:
- {String}
-
{Number} getLayerOrientation()Layer orientation, which is the same as the map orientation
- Returns:
- {Number}
-
{cc.Size} getLayerSize()
- 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)Returns the position in pixels of a given tile coordinate
- Parameters:
- {cc.Point} pos
- 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.Texture2D} getTexture()Return texture of cc.SpriteBatchNode
- Returns:
- {cc.Texture2D}
-
{cc.Sprite} getTileAt(pos)
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} pos
- Returns:
- {cc.Sprite}
-
{Number} getTileFlagsAt(pos)lipped tiles can be changed dynamically
- Parameters:
- {cc.Point} pos
- Returns:
- {Number}
-
{Number} getTileGIDAt(pos)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} pos
- 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 -
removeChild(sprite, cleanup)Remove child
- Parameters:
- {cc.Sprite} sprite
- {Boolean} cleanup
-
removeTileAt(pos)Removes a tile at given tile coordinate
- Parameters:
- {cc.Point} pos
-
setContentSize(size, height)Sets the untransformed size of the TMXLayer.
- Parameters:
- {cc.Size|Number} size
- The untransformed size of the TMXLayer or The untransformed size's width of the TMXLayer.
- {Number} height Optional
- The untransformed size's height of the TMXLayer.
-
setLayerName(layerName)
- Parameters:
- {String} layerName
-
setLayerOrientation(Var)
- Parameters:
- {Number} Var
-
setLayerSize(Var)
- Parameters:
- {cc.Size} Var
-
setMapTileSize(Var)
- Parameters:
- {cc.Size} Var
-
setProperties(Var)
- Parameters:
- {Array} Var
-
setTileGID(gid, pos, 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} pos
- {Number} flags
-
setTiles(Var)
- Parameters:
- {Array} Var
-
setTileSet(Var)
- Parameters:
- {cc.TMXTilesetInfo} Var
-
setupTiles()Creates the tiles