Skip to content

[Bug] Image source for tiled map not found. #18679

@FarotKu

Description

@FarotKu
  • cocos2d-x version: 3-16
  • devices test on: PC
  • developing environments
    • VS version: Community 2015 Update3
    • Tiled version: 1.1.2

For reproduce put .tsx and .tmx in diffrent directory.

File CCTMXXMLParser.cpp; ~430 line:

...
        // build full path
        std::string imagename = attributeDict["source"].asString();
        tileset->_originSourceImage = imagename;

        if (_TMXFileName.find_last_of("/") != string::npos)
        {
            string dir = _TMXFileName.substr(0, _TMXFileName.find_last_of("/") + 1);
            tileset->_sourceImage = dir + imagename;
        }
        else 
...

When buiding path, need add offset between .tmx and .tsx, for example:

...
        // build full path
        std::string imagename = attributeDict["source"].asString();
        tileset->_originSourceImage = imagename;

            //build tileset dir relatively tmx file
        std::string tilesetDir = "";
        std::string tilesetName = tmxMapInfo->_externalTilesetFilename;
        if (tilesetName.find_last_of("/") != string::npos)
        {
            tilesetDir = tilesetName.substr(0, tilesetName.find_last_of("/") + 1);
        }

        if (_TMXFileName.find_last_of("/") != string::npos)
        {
            string dir = _TMXFileName.substr(0, _TMXFileName.find_last_of("/") + 1);
            tileset->_sourceImage = dir + tilesetDir + imagename;
        }
        else 
...

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions