Cocos JS – cc.TMXTiledMap – tile attribute

Hello, I created TMXTiledMap by Tiled editor. I use only 2 types of tiles. Both have attribute called “way”.

TMX file generated by Tiled editor:

<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="isometric" renderorder="right-up" width="16" height="16" tilewidth="192" tileheight="64" nextobjectid="3">
 <tileset firstgid="1" name="tileset_192x64" tilewidth="192" tileheight="64">
  <image source="tileset_192x64.png" width="768" height="512"/>
  <tile id="0">
   <properties>
    <property name="way" value="0"/>
   </properties>
  </tile>
  <tile id="8">
   <properties>
    <property name="way" value="1"/>
   </properties>
  </tile>
 </tileset>
 <layer name="mainLayer" width="16" height="16">
  <data>
   <tile gid="1"/>
   <tile gid="1"/>
   <tile gid="9"/>
...

I get sprite by method getTileAt – works fine. But getTileAt( new cc.p( 0, 0 )).way is undefined. How can I access tile attributes?

Answer:

Instead what I excepted:

map.getLayer( "layerName" ).getTileAt( new cc.p( 0, 0 ) ).way;

use:

map.getPropertiesForGID( map.getLayer( "layerName" ).getTileGIDAt( new cc.p( 0, 0 ) ) )["way"];

Thank you so much for figuring this out.
I had resigned myself to using

map.getLayer("layerName").getTileGIDAt(x,y)

and comparing the tile Id against a list to get data from it.

It looks like you don’t actually need new cc.p(0,0). You can simply use 0,0 ala

map.getPropertiesForGID( map.getLayer( "layerName" ).getTileGIDAt( 0,0 ) )["way"];