Tile map API for Cocos2d-JS

Source: Internet
Author: User

Tile map API for Cocos2d-JS
In order to access tile map, Cocos2d-JS access tile map API, the main classes are: TMXTiledMap, TMXLayer and TMXObjectGroup.
1. TMXTiledMap
TMXTiledMap is a tile map class. Its class chart is shown in. TMXTiledMap is derived from the Node class and has Node features.

Common functions of TMXTiledMap are as follows:
New cc. TMXTiledMap (tmxFile ). Create a tile map object.
GetLayer (layerName ). Obtain the layer object by using the layer name.
GetObjectGroup (groupName ). Obtain the object group set in the layer by using the Object layer name.
GetObjectGroups (). Obtains the set of all object groups in the Object layer.
GetProperties (). Obtain all attributes in the layer.
GetPropertiesForGID (GID ). GID [GID is the global identifier of a tile.] Obtain attributes.
GetMapSize (). Obtain the map size, which is measured in tiles.
GetTileSize (). Obtain the tile size in pixels.


The sample code is as follows:
Var group = _ tileMap. getObjectGroup (Objects );
Var background = _ tileMap. getLayer (Background );
_ TileMap is a tile map object.


2. TMXLayer
TMXLayer is a map layer class. Its Class diagram is shown in. TMXLayer is also derived from the Node class and has Node features. At the same time, TMXLayer is also derived from the SpriteBatchNode class. All TMXLayer objects have batch rendering capabilities. The tile map layer is composed of a large number of repeated images, and they need to be rendered to improve performance.

Common functions of TMXLayer are as follows:
GetLayerName (). Obtain the layer name.
GetLayerSize (). Obtain the layer size, which is measured in tiles.
GetMapTileSize (). Obtain the tile size in pixels.
GetPositionAt (pos ). Pixel coordinates are obtained through tile coordinates. the y-axis direction of tile coordinates is opposite to that of the Y-axis of pixel coordinates.
GetTileGIDAt (pos ). Obtain the GID value through the tile coordinate.


3. TMXObjectGroup
TMXObjectGroup is a collection of object groups in the object Layer. Its Class diagram is shown in. Note that TMXObjectGroup is different from TMXLayer. TMXObjectGroup is not derived from Node and does not have the Node feature.

Common functions of TMXObjectGroup are as follows:
PropertyNamed (propertyName ). Obtain the attribute value through the attribute name.
ObjectNamed (objectName ). Obtain object information by Object Name.
GetProperties (). Obtain the attributes of an object.

GetObjects (). Obtain all objects.

 

 



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.