• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM How to import maps from Tiled?

M

Matheus Carvalho

Guest
I've been looking for a importer but everything I found have the links broken. Is there any program for that or a tutorial teaching to import by coding?
 
T

talien

Guest
Jazzar: "Tiled" is a tile-based map editor that is quite popular (and quite good!)
I was looking for this myself just now. I found some old importers but most seem to be out of date now. I really would like to use Tiled instead of the built-in room editor and really don't feel like writing an importer!
 

TheouAegis

Member
How is the one that you have out of date? What is it in the Importer that you have that renders it no longer viable in studio? If you have the source, I'm sure somebody could tweak the source to make it work in Studio even better.
 
M

Matheus Carvalho

Guest
I have this one that have source code included:
http://gmc.yoyogames.com/index.php?showtopic=583235&hl=tiled

But it works with .xml and Tiled doesn't export to .xml anymore. But apparently the current format .tmx uses .xml language, so could be "easy" to tweak the software and make possible to import .tmx

But, I understand nothing about this.

EDIT:

Notice it's the same as the post above. But the source code is in the first post.
 

MontyDrake

Member
Recently I've been working on maps for an RPG project, and I must say the room editor is far from efficient to make large maps. I really was disappointed when I found it couldn't be done with Tiled. If either there was a way to easily import maps from Tiled, or the room editor got improved with new tools, it would totally rock.
 

Mick

Member
I have made a (free) tool for this, it exports Tiled maps to binary format. The tool supports most of the formats Tiled uses for saving (it also supports object groups and polygon objects etc). You can read more about it and get it here: http://www.gamephase.net/tiled-to-binary-converter/

Code and documentation for Gamemaker Studio can be found here: http://www.gamephase.net/using-files-created-with-tiled-to-binary-converter-in-gamemaker-studio/



  • Supports all map types (orthogonal, isometric, staggered isometric and hexagonal).
  • Can read all compression types available to the tmx file format (uncompressed, base64, zlib and gzip).
  • All tile layers and object groups can be saved separately in their own binary files or multiple layers / groups can be combined in one binary file (tile layers and object groups can’t be combined).
  • Run length encoding available for tile layers, this is a simple compression technique that can greatly reduce the file size of the binary files.
  • All data (except flipping) for objects are saved (names and types optional). Custom properties are saved as 16-bit integers or strings depending on format.
  • All object types are supported (tile, rectangle, ellipse, polygon and polyline).
  • Save tile maps suitable for the extensions Tome and Turbo Plus for AMOS Professional on the Commodore Amiga. (v1.2)
 

Mick

Member
I made the Tiled converter when I started doing a project that needed a really big map. Having a really big room in Gamemaker Studio with a lot of tiles will make saving quite slow. By importing a binary file with the map data that problem is overcome and Tiled is also superior to work in with auto tiling and the terrain tool to mention some of the good features. The converter and the GM:S code for this is documented and there is a demo project loading a map and objects. Should you have any questions, just ask! :)
 
M

Matheus Carvalho

Guest
Woah, that's awesome. Before using it, I have a question: Is it possible to assign objects to binary values?

I don't use tiles in my game, everything is object, so I want to draw in Tiled with tiles, then assign an object for each tile value, like:

Layer 0

1 - obj_floor
2 - obj_grass

Layer 1

1 - obj_grass
2 - obj_sea
 

Mick

Member
Yep you can assign objects to tile values in the tilemap, something like this should work:

Code:
// Load the Tiled map converted to binary
tile_map = load_map("map.bin");

// Store map data in local variables
var list = tile_map[? "layers"];
var layer_count = ds_list_size(list);
var map_width = tile_map[? "width"];
var map_height = tile_map[? "height"];
var map_tile_width = tile_map[? "tile_width"];
var map_tile_height = tile_map[? "tile_height"];

// Create a two dimensional array with object references (different references for every layer)
var objects;
objects[0,0] = noone;
objects[0,1] = obj_floor;
objects[0,2] = obj_grass;
objects[1,0] = noone;
objects[1,1] = obj_grass;
objects[1,2] = obj_sea;

// Iterate the layers of the map
var i, grid, xpos, ypos, value;
for(i = 0; i < layer_count; i++)
{
  // Get layer i
  grid = list[| i];
  for(ypos = 0; ypos < map_height; ypos++)
  {
    for(xpos = 0; xpos < map_width; xpos++)
    {
      // Get value from grid at position
      value = grid[# xpos, ypos];
      // Create the object
      if(value > 0)
        instance_create(xpos*map_tile_width, ypos*map_tile_height, objects[i,value]);
    }
   }
}

You might need to offset the x and y positions for instance_create, depending on the sprite origins for your terrain sprites.
 
Last edited:
M

Matheus Carvalho

Guest
Yep you can assign objects to tile values in the tilemap, something like this should work:

Code:
// Load the Tiled map converted to binary
tile_map = load_map("map.bin");

// Store map data in local variables
var list = tile_map[? "layers"];
var layer_count = ds_list_size(list);
var map_width = tile_map[? "width"];
var map_height = tile_map[? "height"];
var map_tile_width = tile_map[? "tile_width"];
var map_tile_height = tile_map[? "tile_height"];

// Create a two dimensional array with object references (different references for every layer)
var objects;
objects[0,0] = noone;
objects[0,1] = obj_floor;
objects[0,2] = obj_grass;
objects[1,0] = noone;
objects[1,1] = obj_grass;
objects[1,2] = obj_sea;

// Iterate the layers of the map
var i, grid, xpos, ypos, value;
for(i = 0; i < layer_count; i++)
{
  // Get layer i
  grid = list[| i];
  for(ypos = 0; ypos < map_height; ypos++)
  {
    for(xpos = 0; xpos < map_width; xpos++)
    {
      // Get value from grid at position
      value = grid[# xpos, ypos];
      // Create the object
      instance_create(xpos*map_tile_width, ypos*map_tile_height, objects[i,value]);
    }
   }
}

You might need to offset the x and y positions for instance_create, depending on the sprite origins for your terrain sprites.
Man, thank you very much. This will make possible so many interesting things I have in mind. Really, thank you.
 

Mick

Member
I'm glad if this can come to good use. :)

I did a small change to the example I posted: before instance_create I added a check to see if value > 0.
 

rIKmAN

Member
@WitchMaster Thanks for sharing your work, Tiled is a great map editor that is so much better than the room editor.

Just a quick question as I can't test anything until I get home, but does this include any general helper functions/scripts for manipulating the tilemap and retrieving its data, or is it just a loader/converter?

If so, do we just use the normal GM tile commands to interact with it once converted and loaded?

Great work, thanks again! :)
 
Last edited:

Mick

Member
does this include any general helper functions/scripts for manipulating the tilemap and retrieving its data, or is it just a loader/converter?
The map data is read to a ds_map data structure, with the tile layers as ds_grids. I have included examples that use this data to create "normal" tiles (for orthogonal, hexagonal and isometric maps). You can use the data however you wish of course.

do we just use the normal GM tile commands to interact with it once converted and loaded?
Possible or you can use the ds_grids.

I am planning on big updates to this, at the moment also objects from Tiled maps can be loaded but that is not yet perfect. I'm also thinking about automating the import of tilesets into a Gamemaker projects and somehow automatically linking the tile ids, that would save a lot of time, maybe also an option to create normal GM rooms from Tiled maps.
 
B

Beep

Guest
This is very promising!

Would you be able to incorporate user defined depth values for tile layers, and the ability to use more than one tileset per map?
 

Mick

Member
Would you be able to incorporate user defined depth values for tile layers, and the ability to use more than one tileset per map?
Depth values for layers are already definable by the user. The examples only use one tileset, using multiple tilesets will require some extra work but it's doable (how tile ids are handled now is up to the user).
 

rIKmAN

Member
The map data is read to a ds_map data structure, with the tile layers as ds_grids. I have included examples that use this data to create "normal" tiles (for orthogonal, hexagonal and isometric maps). You can use the data however you wish of course.


Possible or you can use the ds_grids.

I am planning on big updates to this, at the moment also objects from Tiled maps can be loaded but that is not yet perfect. I'm also thinking about automating the import of tilesets into a Gamemaker projects and somehow automatically linking the tile ids, that would save a lot of time, maybe also an option to create normal GM rooms from Tiled maps.
Could you be kind enough to give an example of something simple like getting the TileID at the current mouse X/Y?

I'm guessing it involves tile_get_id and tile_layer_find, but as I said I won't be able to test anything til I get home later and am just guessing looking at the docs.

The docs also say tile_get_id uses an index rather than id, which is found using tiles_get_count, but it seems odd that you have to loop through every tile in the map to get the tile id at the current mouse X/Y.

Also is this id the id from within Tiled, or it's place in the tile map image, or something GM specific? ie. Would you use this to check if TileID = 7 (ladder) Then climbing = True?

I'm new to GM so may be misunderstanding things, especially as I can't trial and error at the moment and am just reading the docs.

Are things going to change much with your planned update?

Thanks again.
 
B

Beep

Guest
Depth values for layers are already definable by the user.
Is that by assigning a custom property in Tiled? I've only looked at the scripts fairly briefly, so I'll have to have a dig around and see how it's done
 

rIKmAN

Member
Is that by assigning a custom property in Tiled? I've only looked at the scripts fairly briefly, so I'll have to have a dig around and see how it's done
From what I remember looking at the scripts earlier they are set in the loading script with values from 1000 for layer 0 to -800 to layer 9, but you can just edit them to whatever you want.
 

Mick

Member
Could you be kind enough to give an example of something simple like getting the TileID at the current mouse X/Y?

I'm guessing it involves tile_get_id and tile_layer_find, but as I said I won't be able to test anything til I get home later and am just guessing looking at the docs.
If you use the example script then normal tiles are created and you would use the normal tile finding functions, you can also check the grid ids at mouse_x div TILE_WIDTH and mouse_y div TILE_HEIGHT coordinates.

The docs also say tile_get_id uses an index rather than id, which is found using tiles_get_count, but it seems odd that you have to loop through every tile in the map to get the tile id at the current mouse X/Y.
I'm not sure if I understand what you mean here, you shouldn't need to loop through tiles to get the tile id.

Also is this id the id from within Tiled, or it's place in the tile map image, or something GM specific? ie. Would you use this to check if TileID = 7 (ladder) Then climbing = True?
The ids in the ds_grids are the ones from Tiled which also is it's place in the tile map image. You have two options, either you check which tile is at the position or you check the id in the ds_grid.

Are things going to change much with your planned update?
Things will change, I suspec the tile layers will be the same but the object groups will be handled differently, then I'm also the things I mentioned earlier, also maybe the possibility to export GM rooms (not entirely reqriting the rooms but just rewriting the objects and tiles in the room), and finally the sprite / background import of images used in the Tiled map. I'm planning these currently and will know more shortly.
 

Mick

Member
I'm new to GM so may be misunderstanding things, especially as I can't trial and error at the moment and am just reading the docs.
I recommend you to disect and try to understand the examples, check the rooms in the example project, there are examples for orthogonal, isometric and hexagonal maps.
 

rIKmAN

Member
I'm not sure if I understand what you mean here, you shouldn't need to loop through tiles to get the tile id..
The docs for tile_get_id say:

The "index" argument that the function takes is a real number from 0 up to the number of tiles in the room (which you can find using the tile_get_count() function) and the function will return the corresponding tile id or -1 if no tile with the given index exists.
I'm probably misunderstanding as I can't test anything at the moment, but that reads to me as to get the id of a tile you need to know the index, which you get from looping through all tiles in the room using tile_get_count.

It doesn't make sense really, but it probably will when I can actually run some code and trial and error it.

I recommend you to disect and try to understand the examples, check the rooms in the example project, there are examples for orthogonal, isometric and hexagonal maps.
Yeah I will have a good look through when I get chance, I got a map loaded and displaying but didn't have time to do any proper digging into the scripts.

I'm not new to game dev but am learning how GM wants me to do things.

Thanks for the answers in your previous post, very helpful!

edit: Ah wait, the index is the tile number from Tiled, which I will already know so can use directly in that function, the tile_get_count is just to find the max possible value to use with the function?
 
Last edited:
M

MercuryRich123

Guest
I have made a (free) tool for this, it exports Tiled maps to binary format. The tool supports most of the formats Tiled uses for saving (it also supports object groups and polygon objects etc). You can read more about it and get it here: http://www.gamephase.net/tiled-to-binary-converter/

Code and documentation for Gamemaker Studio can be found here: http://www.gamephase.net/using-files-created-with-tiled-to-binary-converter-in-gamemaker-studio/



  • Supports all map types (orthogonal, isometric, staggered isometric and hexagonal).
  • Can read all compression types available to the tmx file format (uncompressed, base64, zlib and gzip).
  • All tile layers and object groups can be saved separately in their own binary files or multiple layers / groups can be combined in one binary file (tile layers and object groups can’t be combined).
  • Run length encoding available for tile layers, this is a simple compression technique that can greatly reduce the file size of the binary files.
  • All data (except flipping) for objects are saved (names and types optional). Custom properties are saved as 16-bit integers or strings depending on format.
  • All object types are supported (tile, rectangle, ellipse, polygon and polyline).
  • Save tile maps suitable for the extensions Tome and Turbo Plus for AMOS Professional on the Commodore Amiga. (v1.2)
So could I directly import it as a Object or Sprite, or is the code needed for it to work properly? This would save my life if I could directly import it lol.
 
M

MercuryRich123

Guest
You need the code for it to work, using it is quite straightforward, check the privided example (the create code for the rooms).
It's alright just found another way to import the maps. Just make the map the size of your room, then, export the map as an image and make it a sprite in game-maker. Then make an object with that sprite and place it into your room. Done.
 

Mick

Member
It's alright just found another way to import the maps. Just make the map the size of your room, then, export the map as an image and make it a sprite in game-maker. Then make an object with that sprite and place it into your room. Done.
Well that's the easiest solution if you only need an image of the map, for bigger maps it's not so good.
 
T

The_Evil_Dice

Guest
Anyone who's still looking to do this, I ended up just making my own tool to do it, I can't link it, but...
"github.com/The-Evil-Dice/TiledCSVtoGMS/blob/master/README.md"
 
T

The_Evil_Dice

Guest
(It's the paperclip / chain link looking thing on the toolbar at the top of where you type your text when posting)
Thanks, it's because I'm new to the forums.

I've been looking for a good conversion tool that could use Gamemaker's tiles instead of objects, but never found one, so I made it and figured I should share it since this was one of the places I came looking for it, and others seemed to be looking for something similar.
 
T

The_Evil_Dice

Guest
Forgot to clarify before, mine is specifically for Isometric maps made in Tiled, it's also now got a GUI and just takes a .tmx file and pumps out a load of tiles to be pasted into your room file, it also supports a custom boolean parameter in Tiled now called RandomisedHeight, which basically just slightly alters a layers tiles to be randomly slightly above and below each other, which can give a nice effect in some tilesets. I'll keep working on it adding features as an when I need them, but hopefully this makes it much easier for people to make isometric games in gamemaker.

GUI (Or what little is needed):
upload_2017-3-28_1-50-18.png
 
F

Felipe Rybakovas

Guest
Forgot to clarify before, mine is specifically for Isometric maps made in Tiled, it's also now got a GUI and just takes a .tmx file and pumps out a load of tiles to be pasted into your room file, it also supports a custom boolean parameter in Tiled now called RandomisedHeight, which basically just slightly alters a layers tiles to be randomly slightly above and below each other, which can give a nice effect in some tilesets. I'll keep working on it adding features as an when I need them, but hopefully this makes it much easier for people to make isometric games in gamemaker.

GUI (Or what little is needed):
View attachment 8163
Good to see that someone found a solution for this! But i used your jar file and i got no output at all! Can you help ?
 
G

Gyeff

Guest
Good to see that someone found a solution for this! But i used your jar file and i got no output at all! Can you help ?
Same. How do I get this to work? I want to import an isometric map. But, the default export file causes there to be a one cell space in between each tile.
 
Top