How to do: Doors

Hello. I’m preparing a first map in Tiled for my game. Honestly, I’ve never used this software before, and even though it’s quite easy to learn the very basics, i stumbled upon a problem I wish I could handle neatly in editor - not in code; hence I ask.

Before I describe the problem (“problem”?) I’ll just give a small introduction: We are creating a top-down shooter, with gameplay a little similar to that from good ol’ FPS classics, like Doom or Blood.

There are numerous tiles meant to have doors in them. By doors I mean - something that opens up, allowing the player to pass through for some time (after which it closes). That’s the first thing.

The second thing - some of those doors require a specific key to open them.

The third thing: In the first map I have a large trap-room. In the middle of it there’s a new gun to pick up, meant to lie on the “pressure plate” triggering some of the walls to lower and reveal bunch of enemies to eliminate.

Now the thing is, that I have no idea how to handle that problem at all. So far I’ve created some layers - two tile layers (one for background, second for doors and secret passages only) and three layers of objects (first for collision, second for doors, third for secret passages).

Thanks for answers and clues.

Your questions would be specific to the framework you are using to create your game. I’m afraid Tiled – as awesome as it is – can’t solve your problems by itself. :smile:

However, Tiled is a great way to manage the meta data for your levels. However, it’s up to you to do something with those objects in your actual game code. Usually you would just use assign a Type attribute to all the objects and then in your level loading function, loop through all the objects like so (this example uses HaxeFlixel but I would imagine the premise is the same in almost any language):

var myLevel = new TiledLevel("Path/To/Level.tmx");


for (group in myLevel.objectGroups)
    for (o in group.objects)
        switch (o.type.toLowerCase())
            case "door":
                var doorColor = o.custom.get("color");
                myScene.addDoor(o.x, o.y, doorColor);
            case "key":
                var keyColor = o.custom.get("color");
                myScene.addKey(o.x, o.y, keyColor);
            case "enemy":
                var enemyHP = o.custom.get("hp");
                myScene.addEnemy(o.x, o.y, enemyHP);
            case "playerStart":
                myScene.spawnPlayer(o.x, o.y);


It’s up to you to add the logic to your game to handle creation of game objects and adding those objects to the scene. The best way to think of TiledObjects are just placeholders for a position, size and custom attributes. In your case, you would create a class for “pressure plate” that would handle collisions with the player and trigger the action of lowering a wall. A door would just be an object or tile that changes state when the player has a key and collides with it.

Hope this helps at least point you in the right direction!

1 Like