Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect rendering of tilemaps with csv data on windows #20483

Merged
merged 1 commit into from
Mar 23, 2020

Conversation

bolino
Copy link
Contributor

@bolino bolino commented Mar 20, 2020

Each tilemap row would be shifted to the right a certain number of tiles.

When saving Tiled maps with data in CSV format it is saved like this:

<data encoding="csv">
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
</data>

When reading each line there is a carriage return at the beginning which in windows is '\r\n'.
Because of how each line is parsed the '\r' at the beginning of each line would be parsed as a tile id.
On windows we must remove all '\r' from the parsed string.

I had talked about the issue here: https://discuss.cocos2d-x.org/t/cocos2d-x-v4-0-released/48487/106?u=bolin

Each tilemap row would be shifted to the right a certain number of
tiles.
This is caused by the carriage return in windows being '\r\n' and
the way each csv line is parsed.
The '\r' at the beginning of each line would be parsed as a tile id.
On windows we must remove all 'r' from the csv string.
@minggo
Copy link
Contributor

minggo commented Mar 23, 2020

As i know, cocos2d-x doesn't support .csv format. Why not use .xml format?

@bolino
Copy link
Contributor Author

bolino commented Mar 23, 2020

That's what I read in the comments of TMXTiledMap but we've been using csv data for months without problems.
Also if you check TMXMapInfo::endElement(void* /*ctx*/, const char *name) you can see both base64 and csv formats are being parsed.

void TMXMapInfo::endElement(void* /*ctx*/, const char *name)

Csv data is easier to read if you want to examine a level file in text editor and also file sizes are a little bit smaller. I'd also say loading csv data is faster but I haven't done any tests. In newer version of Tiled xml data has been deprecated.

@minggo minggo merged commit 2656646 into cocos2d:v4 Mar 23, 2020
@minggo minggo added this to the v4-next milestone Mar 23, 2020
@bolino bolino deleted the fixTilemapCSV branch May 11, 2020 19:00
Xrysnow pushed a commit to Xrysnow/cocos2d-x that referenced this pull request Jun 21, 2020
…2d#20483)

Each tilemap row would be shifted to the right a certain number of
tiles.
This is caused by the carriage return in windows being '\r\n' and
the way each csv line is parsed.
The '\r' at the beginning of each line would be parsed as a tile id.
On windows we must remove all 'r' from the csv string.
@halx99 halx99 mentioned this pull request Sep 1, 2020
67 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants