Now that I am out of work and have free time, I have dedicated it to programming and other things
I have created some functions that make it possible to load and view files created with the Tiled https://www.mapeditor.org/ in an easy way just by including the "irrTiled.h" file in any project and writing a few lines of code.
In addition to 2d maps you can also create 3d environments with the same editor, I advise looking at the examples for an easy understanding.
This is an example of how to add the code in a project, to do complex things I advise to check the source code of IrrTiled.
Code: Select all
#include "irrTiled.h"
using namespace irr;
using namespace core;
using namespace video;
int main()
{
IrrlichtDevice* device = createDevice(EDT_OPENGL);
device->setWindowCaption(L"irrTiled v1.1 - by TheMrCerebro");
IVideoDriver* driver = device->getVideoDriver();
//==============================================
irrTiled* tld = new irrTiled("media/2dbasic.tmx",device);
//==============================================
while(device->run())
{
driver->beginScene(true, true, SColor(0,200,200,200));
// Extracts data from all tile sets.
for (u32 i = 0; i < tld->Tileset.size(); ++i)
{
TILESET ts = tld->Tileset[i];
// Extracts data from all layers.
for (u32 j = 0; j < tld->Layer.size(); ++j)
{
LAYER lyr = tld->Layer[j];
for (u32 d = 0; d < lyr.Data.size(); ++d)
{
s32 id = lyr.Data[d] - ts.FirstGID;
if (id >= 0)
{
// Tile position.
s32 x = (d % lyr.Size.Width) * tld->TileSize.Width;
s32 y = (d / lyr.Size.Width) * tld->TileSize.Height;
// Draw the tile.
driver->draw2DImage(ts.Image.Texture, vector2di(x, y), ts.SubRects[id], 0, lyr.TintColor, true);
}
}
}
}
driver->endScene();
}
free(tld);
device->drop();
return 0;
}
NEW Version 1.1
Link: https://github.com/TheMrCerebro/irrTiled/releases