IrrTiled - Tile map loader for Irrlicht

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
Post Reply
TheMrCerebro
Competition winner
Posts: 80
Joined: Tue Jun 29, 2010 10:06 pm
Location: Valencia, Spain

IrrTiled - Tile map loader for Irrlicht

Post by TheMrCerebro »

Hello everybody :D !

Now that I am out of work and have free time, I have dedicated it to programming and other things :wink:
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.

Image Image

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
Last edited by TheMrCerebro on Sat Feb 19, 2022 8:21 pm, edited 4 times in total.
Follow me on twitter: @themrcerebro
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: IrrTiled - Tile map loader for Irrlicht

Post by CuteAlien »

Wow, that looks nice. Have to check out in more detail after work :) (bit confused right now how you get the 3d lamps and plants from a 2d editor - all you seem to use in code are boxes, guess I have to see it in action).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
TheMrCerebro
Competition winner
Posts: 80
Joined: Tue Jun 29, 2010 10:06 pm
Location: Valencia, Spain

Re: IrrTiled - Tile map loader for Irrlicht

Post by TheMrCerebro »

Thanks!!! :D

It may seem a bit confusing at first but it is very easy, look at the code:

Code: Select all

 
for (u32 i = 0; i < tld->aObjectGroup.size(); ++i)
    {
        OBJECTGROUP og = tld->aObjectGroup[i];
 
        for (u32 j = 0; j<og.aObject.size(); ++j)
        {
            OBJECT obj = og.aObject[j];
 
            f32 x = obj.x;
            f32 z = obj.y;
 
            if (og.name == "player")
            {
                cam->setPosition(vector3df(-x, 0.0f, z));
            }
            else
            {
                IBillboardSceneNode* sprite = 0;
                sprite = smgr->addBillboardSceneNode(0, dimension2df(tld->tileWidth, tld->tileWidth), vector3df(-x, 0.0f, z));
                sprite->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
                sprite->setMaterialFlag(EMF_BILINEAR_FILTER, false);
 
                if (og.name == "plant")
                    sprite->setMaterialTexture(0, driver->getTexture("plant.png"));
                if (og.name == "lamp")
                    sprite->setMaterialTexture(0, driver->getTexture("lamp.png"));
                if (og.name == "table")
                    sprite->setMaterialTexture(0, driver->getTexture("table.png"));
                if (og.name == "guardian")
                    sprite->setMaterialTexture(0, driver->getTexture("guardian.png"));
            }
        }
    }
 
Simply the trees and the lamps are Billboards/Sprites. I use the position and the name of the objects on the map to locate them and know what they are.
Follow me on twitter: @themrcerebro
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: IrrTiled - Tile map loader for Irrlicht

Post by CuteAlien »

Aah, OK! I only skipped quickly over code earlier and totally missed that :-D
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: IrrTiled - Tile map loader for Irrlicht

Post by CuteAlien »

Got it all working.

Btw, addCameraSceneNodeFPS has a parameter to prevent vertical movement, then you don't need the workaround in the loop.

Also not sure if this are your original project files. There's some tricks in VS, for example you can set the working directory in properties debuggin to your output directory. And if the output directory then is set in a way that it finds data automatically you can directly debug inside VS.

As for the printf warnings in lines like printf("- source: %s\n", ts.source); you have to use ts.source.c_str() as the compiler can't figure out the automatic conversion in this case (printf parameters are a bit typeless).

Anyway - it's really cool. I didn't even know about this map-editor before.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
TheMrCerebro
Competition winner
Posts: 80
Joined: Tue Jun 29, 2010 10:06 pm
Location: Valencia, Spain

Re: IrrTiled - Tile map loader for Irrlicht

Post by TheMrCerebro »

I did the code very quickly, when I saw that everything worked well I published it.
There are many fixes to be made, including the ones you say, irrTiled was just born a few days ago :lol:
About the VC I have started to use it recently, mine was the Code::Block and Mingw but I had to reject it because for other applications it was very basic.

This editor (Tiled) is perfect for making 2D games, whether RPG or action, many engines use it because it is free and quite complete. In my case I would like to add more functions to use it as a level editor in 3D environments, I know it seems crazy but to make games like Wolfenstein, Doom or Duke Nukem 3D it could work.
chronologicaldot
Competition winner
Posts: 688
Joined: Mon Sep 10, 2012 8:51 am

Re: IrrTiled - Tile map loader for Irrlicht

Post by chronologicaldot »

Thank you, TheMrCerebro.
Can't say I have a need for it just yet, but it's nice to have around.
netpipe
Posts: 670
Joined: Fri Jun 06, 2008 12:50 pm
Location: Edmonton, Alberta, Canada
Contact:

Re: IrrTiled - Tile map loader for Irrlicht

Post by netpipe »

please compile it with gcc, makes it more portable. there are about 5 or 6 errors compiling on linux, once its ready I can add it to the Demo's repo.
https://github.com/netpipe/IrrlichtDemos
Live long and phosphor!
-- https://github.com/netpipe/Luna Game Engine Status 95%
TheMrCerebro
Competition winner
Posts: 80
Joined: Tue Jun 29, 2010 10:06 pm
Location: Valencia, Spain

Re: IrrTiled - Tile map loader for Irrlicht

Post by TheMrCerebro »

HI! I have released a new version :wink:
Version 1.1
- Source code cleanup.
- It is possible to load external tilesets in ".tsx" format.
- Improvement in the examples, easier to understand.
- More structures have been added (Group, ImageLayer, Tile, Animation, Frame)
- Images/Sprites corresponding to the game "Wolfenstein 3D" have been removed
to avoid Copyright problems.
See the first post to go to the download link.

...

Hi netpipe, I know it's easy but I don't have that much time to dedicate to this right now, i'm sorry :(
Hi chronologicaldot, Thank you!
Follow me on twitter: @themrcerebro
netpipe
Posts: 670
Joined: Fri Jun 06, 2008 12:50 pm
Location: Edmonton, Alberta, Canada
Contact:

Re: IrrTiled - Tile map loader for Irrlicht

Post by netpipe »

awesome it compiled and ran this time with minimal porting. I shall make some CBP files and upload it to the demos repository soon.
Live long and phosphor!
-- https://github.com/netpipe/Luna Game Engine Status 95%
netpipe
Posts: 670
Joined: Fri Jun 06, 2008 12:50 pm
Location: Edmonton, Alberta, Canada
Contact:

Re: IrrTiled - Tile map loader for Irrlicht

Post by netpipe »

https://github.com/netpipe/IrrlichtDemo ... l/irrTiled will try and fixup the cbp files more after.
Live long and phosphor!
-- https://github.com/netpipe/Luna Game Engine Status 95%
TheMrCerebro
Competition winner
Posts: 80
Joined: Tue Jun 29, 2010 10:06 pm
Location: Valencia, Spain

Re: IrrTiled - Tile map loader for Irrlicht

Post by TheMrCerebro »

Hello! :wink:
I have updated the first post. I just configured irrTiled for use with Code::Blocks and simplified all the examples to be used in an easier way, I have uploaded everything to my github account (I registered a few days ago).
Possibly, soon, upload more examples of its use.
netpipe wrote: Mon Jul 26, 2021 5:43 am https://github.com/netpipe/IrrlichtDemo ... l/irrTiled will try and fixup the cbp files more after.
Thanks netpipe, I just saw your github, thanks for your work! :D
Follow me on twitter: @themrcerebro
netpipe
Posts: 670
Joined: Fri Jun 06, 2008 12:50 pm
Location: Edmonton, Alberta, Canada
Contact:

Re: IrrTiled - Tile map loader for Irrlicht

Post by netpipe »

https://github.com/netpipe/Luna I have also implemented it here inside my game engine.
Live long and phosphor!
-- https://github.com/netpipe/Luna Game Engine Status 95%
Post Reply