Skip to content

Latest commit

 

History

History
88 lines (60 loc) · 2.68 KB

README.md

File metadata and controls

88 lines (60 loc) · 2.68 KB

raylib-tmx

Load Tiled .tmx files for tile maps in raylib, with TMX C Loader.

example/raylib-tmx-example.png

Usage

This is a header-only library. To use it, define RAYLIB_TMX_IMPLEMENTATION in one .c source file before including raylib-tmx.h. You will also have to link its dependencies:

If you're using CMake, libxml2 and zlib come packed in.

Example

#include "raylib.h"

#define RAYLIB_TMX_IMPLEMENTATION
#include "raylib-tmx.h"

int main() {
    InitWindow(800, 450, "[raylib-tmx] example");

    tmx_map* map = LoadTMX("desert.tmx");

    while(!WindowShouldClose()) {

        BeginDrawing();
        {
            ClearBackground(RAYWHITE);
            DrawTMX(map, 0, 0, WHITE);
        }
        EndDrawing();
    }

    UnloadTMX(map);

    CloseWindow();
    return 0;
}

See the example directory for a demonstration of how to use raylib-tmx. Refer to the libTMX documentation to see how to use the tmx_map* map object beyond rendering.

API

tmx_map* LoadTMX(const char* fileName);
void UnloadTMX(tmx_map* map);
Color ColorFromTMX(uint32_t color);
void DrawTMX(tmx_map *map, int posX, int posY, Color tint);
void DrawTMXLayer(tmx_map *map, tmx_layer *layers, int posX, int posY, Color tint);
void DrawTMXTile(tmx_tile* tile, int posX, int posY, Color tint);

Development

To build the example locally, and run tests, use cmake.

git submodule update --init
mkdir build
cd build
cmake ..
make
cd examples
./raylib-tmx-example

Alternatives

This is not the only attempt to get Tiled working in raylib...

Credits

This uses the TMX C Loader, which is licensed under the BSD 2-Clause "Simplified" License. Thank you to Bayle Jonathan for putting it together, and the tmx example this was inspired from.

License

raylib-tmx is licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows static linking with closed source software. Check LICENSE for further details.