New issue
 Projects > js > Issues > Bug #3187

TMXLayer.getProperty(propertyName) doesn't work

Bug #3187 [Closed]
ZippoLag 2013-11-14 19:46 . Updated about 3 years ago

It returns “undefined” regardless of what string is passed as parameter.

linshun 2013-11-22 02:51
  • Assignee set to ludingping
  • Target version set to v2.2.2
ludingping 2013-12-10 06:44

Sebastián Vansteenkiste wrote:

It returns “undefined” regardless of what string is passed as parameter.


This problem has been tested, it works well. step as follow:
1. add some properties to a layer in a tmx file:
@ <layer name="tlBackground" width="10" height="6">
<property name="PointsValue" value="{345,543}"/>
<property name="myTileSize" value="200"/>
<data encoding="base64" compression="zlib">

  1. add some codes to myApp.js in HellowHTML5World app:
    @ var myMap = cc.TMXTiledMap.create(“res/DtMaps.tmx”);
    this.addChild(myMap, 9);
    myMap.setPosition(size.width / 2, size.height / 2);
    var selTMXLayer = myMap.getLayer(“tlBackground”);
    console.log(“myTileSize:” + selTMXLayer.getProperty(“myTileSize”));
    console.log(“PointsValue:” + selTMXLayer.getProperty(“PointsValue”));@

  2. Console outputs the result:

Here is the codes for parsing TMXLayer’s properties in CCTMXXMLParser.js:
@ var layerProps = selLayer.querySelectorAll(“properties > property”);
if (layerProps) {
var layerProp = {};
for (j = 0; j < layerProps.length; j++) {
layerProp[layerProps[j].getAttribute(‘name’)] = layerProps[j].getAttribute(‘value’);

ludingping 2013-12-10 06:46
  • Status changed from New to Closed
  • % Done changed from 0 to 100
ZippoLag 2013-12-10 18:13

I see..

I was misusing the code now that I look at it.

You see, Tiled allows for giving properties to the tmx file itself (which is the logical place to store some properties, and not on some arbitrary layer) and that was the property I wanted to get.

The xml would look like:

<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" width="3" height="7" tilewidth="64" tileheight="64">
<property name="optimo" value="5"/>
<tileset firstgid="1" name="piso" tilewidth="64" tileheight="64">
<image source="piso.png" width="64" height="64"/>

Is there a way to get the value of “optimo” in my example?

ludingping 2013-12-11 02:28


The cc.TMXTiledMap has a function “getProperty”.

for example:
var myMap = cc.TMXTiledMap.create("res/DtMaps.tmx");

ZippoLag 2013-12-12 03:19

And that’s the method that keeps returning “undefined” no matter what.

ludingping 2013-12-13 02:54

Thanks for your feedback.

This bug has been fixed. more details at:

Best regards

ZippoLag 2013-12-13 22:18

Thank you, and sorry for the extra work from me not specifying the bug properly.

Atom PDF

Start date:2013-11-14
Due date:
% Done:


Target version:v2.2.2

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.