Static tile properties with Tiled

I’ve been searching around and cant seem to find it…I may be wording it wrong. Is it possible to make tile properties static? Like, for instance:

If i make a map and set a blocked property for all of the blocked tiles, then when I go to make a second map, I don’t want to have to set all the same tiles with blocked again…Is there a way to do this in tiled or with code? Or do I need to learn to make my own map editor?

I don’t know if it is a good idea or not, as I’m fairly new to this, but I have a layer that is always at the bottom in my tiled maps. In the code, I do collision detection based on if that layer has a tile there or not.

It just seems like it would be redundant to draw a whole extra layer every time just for collision. That’s how I did it in my pacman game, but being there are a lot more tiles that will always be blocked and quite a few maps…It doesn’t seem like that would be a good approach for this.

I’m not really sure if this is what you mean but you can set properties to tiles in Tiles. Let’s say you have a wall tile. Then you set a property “blocked” to the tile and all walls will be blocked. You shouldn’t have to add an extra collision layer since you already have that information in the tiles with “blocked” property.

I know…That’s exactly what i’m doing, but I have multiple maps. I’m trying to figure out how to set it once and every map that I make with that tileset has the same properties so I don’t have to set the properties a hundred times. I’m not doing anything with a collision layer. That’s what syath was suggesting but it doesn’t apply to my game.

Are you using this for collision detection? simply have set block types and in the blocks that are walls and dont allow objects through create a method Blocksplayer. If it returns true then your player cannot move through that tile, should work for static and non static as it isnt dependent on local situations.

you can externalised the tileset in the editor

Im making a game with tiled currently and i dont use tile properties i have object layar called “collision” within that layer i have rectangle objects. in my gameMap class i create “Shape” ArrayLists and with for loops fill the arraylists with “new Rectangles()”

for (int i = 0; i < super.getObjectCount(collGroup); i++) {

			Rectangle collisionRect = new Rectangle(super.getObjectX(collGroup, i),
					super.getObjectY(collisionGroup, i), super.getObjectWidth(
							collisionGroup, i), super.getObjectHeight(collisionGroup, i));
			collisionShapes.add(collisionRect);
		}

Like he said you can right click the .txm file and edit it manually (its written in XML i think) make one tile property then copy paste it to the tles you need on different maps.

I think you are the only one who understands what i’m asking…

I already know how i’m doing my collision. Each blocked tile will have a property set as blocked. In tiled, I don’t want to go through EVERY one of my maps setting EVERY tile property again. I’d rather set it once in a map or in code and not have to set the tiles properties again every time I make a new map as I have a lot of maps.

I could edit the map properties, but I don’t think libgdx reads maps in XML. They are encoded.

I think it should be possible to do in code, when you load your tmx, to check which tileset and wich tile a cell belongs to. Like this you could define a mapping (either in code or in an external text file). Then you just need to check if the level cell belongs to the blocked tiles.

I’m commuting right now, so I can’t make any example code. But it should be pretty straight forward to implement.
Maybe you could tell us what library you use to load the tmx (slick, libgdx or something different?)

Edit:
A short piece of code of how it could look like in libgdx with TiledMap (but it is not tested, so maybe you have to fiddle around a bit).

This code iterates through all tile sets and tiles. The isBlockingTile method simply checks some constraints (in this case the tilesets name needs to be “foo” and the tile id 2 or 4) and if they are met, it adds the property to the tile.


   public void bar() {
      TiledMap map = null;
      // TODO: Load tiled map
      TiledMapTileSets sets = map.getTileSets();
      for (TiledMapTileSet set : sets) {
         for (TiledMapTile tile : set) {
            if (isBlockingTile(set, tile)) {
               tile.getProperties().put("blocks", true);
            }
         }
      }
   }

   private boolean isBlockingTile(TiledMapTileSet set, TiledMapTile tile) {
      String name = set.getName();
      if (name == "foo" && (tile.getId() == 2 || tile.getId() == 4)) {
         return true;
      }
      return false;
   }


I didn’t think about that. That’s a great idea. I’ll just do all of my tile properties in code at run-time. I didn’t even know you could do that but that will take care of my problem i’m pretty sure.