Loading TMX file not working correctly on anchor center

  ... in the unlikely case you discovered a bug, post it here.

Loading TMX file not working correctly on anchor center

Postby AlejandroAyala » Wed Aug 06, 2014 11:48 pm

Hi,

I was working with TMX, after loading the file I realize that the layers were correctly placed, but the objects were not.

I found a simple solution, adding half of the width to the X coord of the object and half of the heigth to the Y coord on the TMXObject class like so

Before:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public TMXObject(final Attributes pAttributes)
  2. {
  3.         this.mName = pAttributes.getValue("", TMXConstants.TAG_OBJECT_ATTRIBUTE_NAME);
  4.         this.mType = pAttributes.getValue("", TMXConstants.TAG_OBJECT_ATTRIBUTE_TYPE);
  5.         this.mX = SAXUtils.getIntAttributeOrThrow(pAttributes, TMXConstants.TAG_OBJECT_ATTRIBUTE_X);
  6.         this.mY = SAXUtils.getIntAttributeOrThrow(pAttributes, TMXConstants.TAG_OBJECT_ATTRIBUTE_Y);
  7.         this.mWidth = SAXUtils.getIntAttribute(pAttributes, TMXConstants.TAG_OBJECT_ATTRIBUTE_WIDTH, 0);
  8.         this.mHeight = SAXUtils.getIntAttribute(pAttributes, TMXConstants.TAG_OBJECT_ATTRIBUTE_HEIGHT, 0);
  9. }
  10.  
Parsed in 0.012 seconds, using GeSHi 1.0.8.4

After:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public TMXObject(final Attributes pAttributes) {
  2.                 this.mName = pAttributes.getValue("", TMXConstants.TAG_OBJECT_ATTRIBUTE_NAME);
  3.                 this.mType = pAttributes.getValue("", TMXConstants.TAG_OBJECT_ATTRIBUTE_TYPE);
  4.                 this.mWidth = SAXUtils.getIntAttribute(pAttributes, TMXConstants.TAG_OBJECT_ATTRIBUTE_WIDTH, 0);
  5.                 this.mHeight = SAXUtils.getIntAttribute(pAttributes, TMXConstants.TAG_OBJECT_ATTRIBUTE_HEIGHT, 0);
  6.                 this.mX = SAXUtils.getIntAttributeOrThrow(pAttributes, TMXConstants.TAG_OBJECT_ATTRIBUTE_X)+(mWidth/2);
  7.                 this.mY = SAXUtils.getIntAttributeOrThrow(pAttributes, TMXConstants.TAG_OBJECT_ATTRIBUTE_Y)+(mHeight/2);
  8.         }
  9.  
Parsed in 0.011 seconds, using GeSHi 1.0.8.4


after that another problem came out, now the objects are inverted on the y axis,

I dont know if this is a bug or not but I thought it worth posting

By the way sorry about my english, I dont speak it very well
AlejandroAyala
 
Posts: 1
Joined: Wed Aug 06, 2014 11:35 pm

Return to Bugs

Who is online

Users browsing this forum: No registered users and 3 guests