TMX map and layer properties

  ... the case you feel the need for a new feature or want to submit one.

TMX map and layer properties

Postby moraes » Sun Oct 10, 2010 1:20 pm

Hey!
I'm new here, and an Android newbie too. :)

I started to create a game with AndEngine and I'm enjoying it so far. Maybe I'm missing something, but can we read arbitrary TMX map and layer properties? I intended to load a map and store there the tiled background to be used for the level, as in:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <map height="8" orientation="orthogonal" tileheight="32" tilewidth="32" version="1.0" width="8" background="gfx/my_background.png">
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


I started to implement it, and there's a lot to override, so before I go further, let me ask: is there any way to access arbitrary map/layer properties currently? And what would be the proper way to implement it -- add listeners for map and layer as there's one for tiles?

thanks for the hard work. :)
moraes
 
Posts: 9
Joined: Wed Oct 06, 2010 10:04 am
Location: Brazil

Re: TMX map and layer properties

Postby moraes » Sun Oct 10, 2010 2:31 pm

This is my temporary solution: diff.

Since a map (and layers) are not numerous, I'd load all their attributes on construction and make them available. I'd refactor this to reuse the attributes from the HashTable later instead of getting one by one (mOrientation, mTileColumns etc), but wanted to not change much of the original code initially. Is this a good idea?
moraes
 
Posts: 9
Joined: Wed Oct 06, 2010 10:04 am
Location: Brazil

Re: TMX map and layer properties

Postby Nicolas Gramlich » Sun Oct 10, 2010 7:25 pm

So the "background"-attribute in the "map"-tag a custom/"non-standard" one :?:
In that case I most likely won't implement it :|

Best Regards,
Nicolas
Nicolas Gramlich
Site Admin
 
Posts: 1734
Joined: Mon Jun 07, 2010 6:20 pm
Location: Schriesheim, Germany

Re: TMX map and layer properties

Postby moraes » Sun Oct 10, 2010 7:57 pm

Could be <property> tags too:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <map version="1.0" orientation="orthogonal" width="8" height="8" tilewidth="32" tileheight="32">
  2.  <properties>
  3.   <property name="background" value="gfx/my_background.png"/>
  4.  </properties>
  5. <!-- ... -->
  6. </map>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


I was silly to add an extra attribute. I overlooked how extra properties were defined in tiles; maps can have them too.
moraes
 
Posts: 9
Joined: Wed Oct 06, 2010 10:04 am
Location: Brazil

Re: TMX map and layer properties

Postby moraes » Sun Oct 10, 2010 10:59 pm

Please consider this:

http://code.google.com/r/rodrigomoraes- ... ac8974a448

It loads <properties> for maps. Next step is to do the same for layers.
moraes
 
Posts: 9
Joined: Wed Oct 06, 2010 10:04 am
Location: Brazil

Re: TMX map and layer properties

Postby moraes » Mon Oct 11, 2010 12:09 am

moraes wrote:Next step is to do the same for layers.


And here it is:

http://code.google.com/r/rodrigomoraes- ... 8cce06d05c

:)

On another subject, I wonder why TMXProperties is not some kind of MultiMap, I mean, Map<String, List<String>>. It would probably provide a better API to retrieve values from tiles, layers and maps.
moraes
 
Posts: 9
Joined: Wed Oct 06, 2010 10:04 am
Location: Brazil

Re: TMX map and layer properties

Postby Nicolas Gramlich » Tue Oct 12, 2010 6:46 pm

Hi,

I finally stumbled over the official schema definition:

http://sourceforge.net/apps/mediawiki/t ... Map_Format

Found that:
<properties>

Can contain: property

Wraps any number of custom properties. Can be used as a child of the map, tile (when part of a tileset), layer, objectgroup and object elements.


I think the last thing missing now is "TMXObjectGroupProperty" :)

Best Regards,
Nicolas
Nicolas Gramlich
Site Admin
 
Posts: 1734
Joined: Mon Jun 07, 2010 6:20 pm
Location: Schriesheim, Germany

Re: TMX map and layer properties

Postby moraes » Tue Oct 12, 2010 7:08 pm

Nicolas Gramlich wrote:Hi,

I finally stumbled over the official schema definition:

http://sourceforge.net/apps/mediawiki/t ... Map_Format


Yeah, just recently I discovered that there're .xsd and .dtd in the repository (the developer said they are recent):

http://gitorious.org/tiled/tiled-qt/trees/master/docs

Don't you think that a custom HashMap would be more appropriate to store the properties? We would not need to iterate over all to read a single one is what I'm thinking.
moraes
 
Posts: 9
Joined: Wed Oct 06, 2010 10:04 am
Location: Brazil

Re: TMX map and layer properties

Postby Nicolas Gramlich » Tue Oct 12, 2010 10:15 pm

Hi,

hm using a HashMap<String, ArrayList<String>> would require an additional Map.Entry and a ArrayList<String> to be created compared to just one TMXProperty (for the current way) for each TMXProperty. So the current solution probably wins in memory efficiency.

I haven't seen to many TMX files yet, but I assume that the properties usually can be efficiently iterated over. :|
One the other hand, one probably knows what TMXProperty he is looking for so the quicker lookup would be nice too ... :?

Best Regards,
Nicolas
Nicolas Gramlich
Site Admin
 
Posts: 1734
Joined: Mon Jun 07, 2010 6:20 pm
Location: Schriesheim, Germany

Re: TMX map and layer properties

Postby moraes » Tue Oct 12, 2010 10:36 pm

Nicolas Gramlich wrote:hm using a HashMap<String, ArrayList<String>> would require an additional Map.Entry and a ArrayList<String> to be created compared to just one TMXProperty (for the current way) for each TMXProperty. So the current solution probably wins in memory efficiency.


Hmm, ok, you're probably right. Really I should just go and create some helper methods to access them more easily.

Oh, thanks for merging it. :)
moraes
 
Posts: 9
Joined: Wed Oct 06, 2010 10:04 am
Location: Brazil

Next

Return to Features

Who is online

Users browsing this forum: No registered users and 5 guests