Question

I am trying to count tiles in my layer with wall properties true. In my TMX file I have set up the property so I am sure it is there as you can see here:

TMX XML:

<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" width="212" height="20" tilewidth="16"   
tileheight="16">
 <tileset firstgid="1" name="tileSet-hd" tilewidth="16" tileheight="16">
 <image source="gfx/tile_set.png" trans="fe80fe" width="256" height="256"/>
 </tileset>
<layer name="background" width="212" height="20">
<data encoding="base64" compression="zlib">

  </data>
 </layer>
 <layer name="walls" width="212" height="20">
  <properties>
   <property name="wall" value="true"/>
  </properties>
  <data encoding="base64" compression="zlib">

  </data>
 </layer>
 <layer name="hazards" width="212" height="20">
  <data encoding="base64" compression="zlib">

  </data>
 </layer>
</map>

CODE:

 try {
 final TMXLoader tmxLoader = new TMXLoader(activity.getAssets(),
                activity.getTextureManager(),
                TextureOptions.BILINEAR_PREMULTIPLYALPHA,
                engine.getVertexBufferObjectManager(),
                new ITMXTilePropertiesListener() {
                    @Override
                    public void onTMXTileWithPropertiesCreated(
                            final TMXTiledMap pTMXTiledMap,
                            final TMXLayer pTMXLayer,
                            final TMXTile pTMXTile,
                            final 
TMXProperties<TMXTileProperty> pTMXTileProperties) {

if 
(pTMXTileProperties.containsTMXProperty("wall","true")) {
mTilesCount++;
}

}
});
        this.mTMXTiledMap = tmxLoader.loadFromAsset("gfx/level1.tmx");
        Log.d("aaaaaa", "tiles count: " + mTilesCount);
    } catch (final TMXLoadException e) {
        Debug.e(e);
    }

    final TMXLayer tmxLayerBcg = this.mTMXTiledMap.getTMXLayers().get(0);
    final TMXLayer tmxLayerWalls = this.mTMXTiledMap.getTMXLayers().get(1);
    final TMXLayer tmxLayerTraps = this.mTMXTiledMap.getTMXLayers().get(2);
    gameScene.attachChild(tmxLayerBcg);
    gameScene.attachChild(tmxLayerWalls);
    gameScene.attachChild(tmxLayerTraps);
    // end of loading TMX

In the conclusion I want to have created tiles on which my player can step on, as walls. But I can't even move yet from this issue. Log always show tiles count: 0. But why, if there is property with name wall and value true.

I was guided by few tutorials and used these examples:

This code

Properties in TMX

Était-ce utile?

La solution

You must create objects in tiled editor in Object layer. And then draw the objects in Java, set them invisible so background will be seen instead.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top