Using libtmx-parser to load tilemaps c++

I’ve found that this library is incredibly useful and straightforward. I’ve found out how to load width and height, but I can’t figure out how to store the “map” portion of the tmx. I believe the library stores it in a type of vector, but I can’t convert the vector to a vector<int>.

Could you be a little more specific? It’s impossible to help you based on this message short of trying out libtmx-parser myself and explaining how I used it. Try showing some code and maybe the compiler error if you’re getting one.

Edit: Ok, I see you didn’t `-quote the code so the forum was trying to display it as HTML. I’ve fixed that now. Still, there could be some more info like what type does the original vector store and why do you need it in a vector of ints?

That’s the problem. I have no idea what type it’s storing the data as. The tiles can be stored as ints or chars, I don’t care, ints are just easier to deal with. When I looked through the .cpp, it’s storing them in a TmxTilesetCollection_t, but there is no class or struct that defines what that is.

Hmm, when I looked at tmxparser.h I see the following:

typedef std::vector<TmxTileset> TmxTilesetCollection_t;

And the definition of the TmxTileset struct is right above that.

However, this thing stores information about tilesets, not tiles. If you want to look at the tile data, you’ll need to look at this part:

typedef struct
    unsigned int gid;
    unsigned int tilesetIndex;
    unsigned int tileFlatIndex;
    bool flipX, flipY, flipDiagonal;
} TmxLayerTile;

typedef std::vector<TmxLayerTile> TmxLayerTileCollection_t;

You should really just start from the bottom at libtmx-parser/tmxparser.h at master · halsafar/libtmx-parser · GitHub where you see TmxMap defined and you can then figure out how to get at the tiles.

For example, to get the global ID of the first tile from the first layer, you would do:


I hope you can figure it out from here. The definition of everything is available right there.

I couldn’t possibly thank you enough, I didn’t notice that part. I got the majority of my engine working now, thanks!