baylej/tmx

Name and value of properties not matching

AliceRixte opened this issue · 3 comments

Hi!
I use your library with SDL and the name and the values of the properties are not matching.
For instance, when I write in Tiled
Direction -> RIGHT
firs_row_pos_x -> 0
first_rox_pos_y -> 8
row_number -> 4
I get that after using your xml parser :
Direction -> 8
firs_row_pos_x -> 4
first_rox_pos_y -> 0
row_number -> RIGHT

Maybe I did something wrong but this is weird... Is their a way to fix it?

[EDIT] I'm very sorry, indeed I did something wrong... Seems their is no way to delete this post so, sorry to bother you with that...

Hi @141592653 ,

Tell us whenever you find something hard to understand or to use, then I or somebody else can write documentation/improve the library.

TMX stores the properties in the reverse order than they are read from the file. (btw Tiled gives no guarantee on the order it writes data in the file (xml or json)).

Kind regards.
Jonathan.

OK. Thank you... I realised that it was reversed just after the post but that makes sense... For the moment, I'm quite new to all this stuff but it wasn't very difficult to understand, reading the tmx.h file is enough to understand how it works..For me you did a very nice job.

Concerning what could be improved, i think that adding terrain parsing would be the best improve (unless it has been already done?). Another thing is that it is impossible to pass a function to tmx_img_load_func which creates directly an SDL_Texture* because we need to pass the SDL_Renderer in argument so I have to convert by hand after the load of the map all the images.

Sorry for my mistakes in English (I'm french),
Kind regards.
@141592653

Hi again,

TMX does not load terrain infos at the moment and it's not on my personal todolist because I think it is not meant to be use in games, feel free to open an issue if you need it.

For SDL image to texture loading, you could add a global variable and use it in your own function:

static SDL_Renderer *ren;

void* load_image_to_sdl_texture(const char *path) {
    SDL_Surface *surface = IMG_Load(path);
    return SDL_CreateTextureFromSurface(ren, surface);
}

/* ... */

tmx_img_load_func = load_image_to_sdl_texture;

If you don't want to use globals, your current solution is probably the best.