Skip to content

FlxTilemap.loadMap doesn't respect trailing whitespace in CSV files #1550

@rrohrer

Description

@rrohrer

I'm calling loadmap as such:

foo.loadMap(Assets.getText("assets/foo.txt"), "assets/my_image.png", x, y, FlxTilemap.OFF);

with a foo.txt that looks like:

0,0,0,0,0
1,0,0,0,0
0,0,0,0,0
0,0,0,0,0
1,1,1,1,1
~this is a newline character~

having a newline character at the end of the file (to make it a valid text file), which is allowed by the CSV format causes this call to silently fail.

On OSX under the neko and native target I'm getting back:

trace(foo.widthInTiles); // this prints 0

Looking into how FlxTilemap is implemented if the last line is a newline, it fails the whole call (silently).

To fix this, you need to call loadMap as such:

foo.loadMap(StringTools.rtrim(Assets.getText("assets/foo.txt")), "assets/my_image.png", x, y, FlxTilemap.OFF);

It seems like it would make more sense to have that call to StringTools.rtrim in loadMap, or at the very least throw an exception saying that whitespace isn't allowed at the end of the CSVs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions