Supporting TMX objects with no width and height.

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

Supporting TMX objects with no width and height.

Postby oulette » Sat Nov 06, 2010 3:25 pm

Hi, first post, new to AndEngine, loving it so far. I'm porting something I was doing with Rokon. I had coded my own TMX importer but it was pretty crappy. Moving my maps to your (super awesome) tmx importer I did run into a small irritant. All my objects have no width and no height. They're basically dots. Loading the TMXObject.java code, I see this could probably be implemented rather simply by changing line 37-38 from this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                 this.mWidth = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_OBJECT_ATTRIBUTE_WIDTH);
  2.                 this.mHeight = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_OBJECT_ATTRIBUTE_HEIGHT);
  3.  
Parsed in 0.011 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. try{
  2.                 this.mWidth = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_OBJECT_ATTRIBUTE_WIDTH);
  3.                 this.mHeight = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_OBJECT_ATTRIBUTE_HEIGHT);
  4.                 }catch(java.lang.IllegalArgumentException iae){
  5.                   this.mWidth = 0;
  6.                   this.mHeight = 0;
  7.     }
  8.  
Parsed in 0.011 seconds, using GeSHi 1.0.8.4


I'm not sure if my catch is declared properly, I have tried to replace my .jar with the sources but I got all sorts of errors. Scared I scurried back to the .jar. So this code is untested. Eventually I'll move to source to submit these as patches instead. Any tutorial on building/linking straight to the source?

Thank you very much, the engine rocks my world so far! Cheers!
oulette
 
Posts: 18
Joined: Sat Nov 06, 2010 3:14 pm

Re: Supporting TMX objects with no width and height.

Postby Nicolas Gramlich » Sat Nov 06, 2010 3:59 pm

Oh I see when one just clicks on the map using Tiled, no width and height attributes are created :)
(I though width/height were a must.)

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. this.mWidth = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_OBJECT_ATTRIBUTE_WIDTH);
  2. this.mHeight = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_OBJECT_ATTRIBUTE_HEIGHT);
Parsed in 0.011 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. this.mWidth = SAXUtils.getIntAttribute(pAttributes, TAG_OBJECT_ATTRIBUTE_WIDTH, 0);
  2. this.mHeight = SAXUtils.getIntAttribute(pAttributes, TAG_OBJECT_ATTRIBUTE_HEIGHT, 0);
Parsed in 0.011 seconds, using GeSHi 1.0.8.4


Fix will be online in a few seconds :)

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

Re: Supporting TMX objects with no width and height.

Postby Nicolas Gramlich » Sat Nov 06, 2010 4:01 pm

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

Re: Supporting TMX objects with no width and height.

Postby oulette » Sat Nov 06, 2010 4:26 pm

Thanks! Never played with SAXUtil so I didn't know about the "getIntAttribute" method. Though from the name "getIntAttributeOrThrow" I should've figured it out :)
oulette
 
Posts: 18
Joined: Sat Nov 06, 2010 3:14 pm


Return to Features

Who is online

Users browsing this forum: No registered users and 7 guests