Extracting tiled metadata in slick2d

This is a cross post from the slick2d forums, I’m also posting it here as their forum does not appear to be very active.

Hi,

I’m attempting to implement some very basic collision detection for my tiled map. I’ve created a new map in tiled with two tilesets (each containing one image, grass and rocks). I’ve first drawn some grass tiles, and then some rocks above them. I then right clicked on the rocks layer and set layer properties to blocked and true. I’ve also inspected the XML in the file and the property is definitely there.

In my code I run the following nested for loop to build a two dimensional array of tiles that contain the blocked attribute.


for (int xAxis=0;xAxis<map.getWidth(); xAxis++) 
        { 
                     for (int yAxis=0;yAxis<map.getHeight(); yAxis++) 
                     { 
                          
                        int tileID = map.getTileId(xAxis, yAxis, 0); 
                         String value = map.getTileProperty(tileID, "blocked", "false"); 
                         //System.out.println("value is " + value); 
                         if (value.equalsIgnoreCase("true")) 
                         { 
                            System.out.println("tile id" + tileID + "is BLOCKED"); 
                             blocked[xAxis][yAxis] = true; 
                         } 
                     } 
         }


However none of the tiles are ever detected as having the blocked attribute. I’ve confirmed the index of the layer rocks by calling getLayerIndex(“rocks”) however it still doesn’t work.

I’d be extremely grateful for any suggestions as this is very very frustrating.

Epic fail on my part as I’ve only just been introduced to tiled I was not aware that there was a distinction between a tile in the tileset having a property and the whole tileset having a property. Once I attached a property to the individual tile it worked.

What a crap first post :smiley:

::slight_smile: