Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Static tile properties with Tiled  (Read 639 times)
0 Members and 1 Guest are viewing this topic.
Offline Bassex96

Senior Devvie


Medals: 4



« Posted 2014-01-25 02:07:02 »

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?
Offline syath

Junior Newbie





« Reply #1 - Posted 2014-01-25 02:21:20 »

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.
Offline Bassex96

Senior Devvie


Medals: 4



« Reply #2 - Posted 2014-01-25 02:35:48 »

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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Axeman

Senior Devvie


Medals: 7



« Reply #3 - Posted 2014-01-25 02:48:22 »

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.
Offline Bassex96

Senior Devvie


Medals: 4



« Reply #4 - Posted 2014-01-25 02:55:53 »

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.
Offline lcass
« Reply #5 - Posted 2014-01-26 10:29:43 »

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.
Offline cedricb

Innocent Bystander





« Reply #6 - Posted 2014-01-26 11:59:04 »

you can externalised the tileset in the editor
Offline OracleArts

Senior Newbie





« Reply #7 - Posted 2014-01-26 15:03:52 »

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()"
1  
2  
3  
4  
5  
6  
7  
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);
      }
Offline OracleArts

Senior Newbie





« Reply #8 - Posted 2014-01-26 15:12:06 »

you can externalised the tileset in the editor


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.
Offline Bassex96

Senior Devvie


Medals: 4



« Reply #9 - Posted 2014-01-27 19:40:12 »

you can externalised the tileset in the editor


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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline atombrot
« Reply #10 - Posted 2014-01-28 16:32:21 »

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.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
   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;
   }
Offline Bassex96

Senior Devvie


Medals: 4



« Reply #11 - Posted 2014-01-30 20:07:31 »

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.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (29 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (40 views)
2014-12-09 22:41:13

BurntPizza (75 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (47 views)
2014-11-29 21:32:03

toopeicgaming1999 (114 views)
2014-11-26 15:22:04

toopeicgaming1999 (102 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!