Use Tiled maps in raylib, through Tileson.
#include "raylib.h"
#define RAYLIB_TILESON_IMPLEMENTATION
#include "raylib-tileson.h"
int main(int argc, char* argv[]) {
InitWindow(800, 450, "[raylib-tileson] example");
SetTargetFPS(60);
// Load the map
Map map = LoadTiled("resources/desert.json");
while (!WindowShouldClose()) {
BeginDrawing();
{
ClearBackground(RAYWHITE);
// Draw the map
DrawTiled(map, 0, 0, WHITE);
}
EndDrawing();
}
// De-Initialization
UnloadMap(map);
CloseWindow();
return 0;
}
- raylib ~5.5
- C++17 or higher
Map LoadTiled(const char* fileName);
Map LoadTiledFromMemory(const unsigned char *fileData, int dataSize, const char* baseDir);
bool IsTiledReady(Map map);
void DrawTiled(Map map, int posX, int posY, Color tint);
void UnloadMap(Map map);
While raylib-tileson does compile and run from C, it requires compilation with C++17. Mixing C and C++ may not be preferable by all, so there could be a desire to use an alternative...
mkdir build
cd build
cmake ..
make
./example/raylib-tileson-example
raylib-tileson is licensed under the BSD 2-Clause License, see LICENSE for more information.