Projects > cpp > Issues > Bug #2050

We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.

Create Issue on Github

CCTMXMap doesn't support TMX files reference external TSX files

Bug #2050 [Closed]
zhangxm 2013-04-12 03:03 . Updated almost 3 years ago

This is reported by marmalade developer, the detail description is:

Hi guys

We are proposing the following fix to CCTMXMapInfo::startElement().

The current code does not seem to support TMX files referencing external TSX files; if the TMX file specifies a “firstgid” greater than 0 (which is usually the case… it’s usually 1) then this value is not used when parsing the TSX file, therefore all tile gids are offset incorrectly.

Ideally this code would respect any “firstgid” property already set on the TMX object; otherwise, it should simply set the value to 1 if it comes back from the parser as 0 (which is our implementation below):

(around line 365)

else
{
CCTMXTilesetInfo *tileset = new CCTMXTilesetInfo();
tileset~~>m_sName = valueForKey;
tileset~~>m_uFirstGid = (unsigned int)atoi(valueForKey(“firstgid”, attributeDict));

// MARMALADE
// m_uFirstGid must be minimum of 1, as 0 means “no tile”.
// If the TMX file references an external tileset (TSX), then the TSX file
// does not specify a “firstgid” property (at least, not if exported from the
// ‘Tiled’ editor. The code here either needs to inherit the “firstgid” property
// from the TMX file, or ensure that it is non-0
if (!tileset~~>m_uFirstGid)
tileset~~>m_uFirstGid = 1;

tileset~~>m_uSpacing = atoi);
tileset~~>m_uMargin = (unsigned int)atoi(valueForKey(“margin”, attributeDict));
CCSize s;
s.width = (float)atof(valueForKey(“tilewidth”, attributeDict));
s.height = (float)atof(valueForKey(“tileheight”, attributeDict));
tileset~~>m_tTileSize = s;
pTMXMapInfo~~>getTilesets()~~>addObject;
tileset~~>release();
}

zhangxm 2013-04-23 02:02
  • Assignee set to zhangxm
zhangxm 2013-04-23 03:43
  • Target version changed from cocos2d-2.1rc0-x-2.1.3 to Candidate

Logical code of CCTileMap is changed, should decide how to do in new codes.

zhangxm 2013-09-29 09:23
  • Target version changed from Candidate to 3.0-alpha1
zhangxm 2013-11-16 09:52
  • Assignee changed from zhangxm to boyu0
  • Target version changed from 3.0-alpha1 to 3.0-beta
boyu0 2013-12-20 03:40

I tested it at tiled editor, and I think both description above and our engine both wrong with parse firstgid.
This is how the firstgid works at tiled editor:
1. firstgid is ignored at tsx file, no mater what firstgid value is setted at tmx or tsx file, it always start at 0.
2. gid=0 is always an empty tile at map, even if firstgid is set to 0.
3. if firstgid is not setted, it always equal to 0, even it setted at tsx file.
4. if firstgid setted less than 0, it setted to 0
I will follow tiled editor to fix this bug.

boyu0 2013-12-31 07:19
  • Status changed from New to Closed
  • % Done changed from 0 to 100

Applied in changeset commit:f3193c7f03deac04de077f915d6b934fbde87797.

Atom PDF

Status:Closed
Start date:2013-04-12
Priority:Normal
Due date:
Assignee:boyu0
% Done:

100%

Category:all
Target version:3.0-beta

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.