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?
// 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]);
}
}
}
Man, thank you very much. This will make possible so many interesting things I have in mind. Really, thank you.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.
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.does this include any general helper functions/scripts for manipulating the tilemap and retrieving its data, or is it just a loader/converter?
Possible or you can use the ds_grids.do we just use the normal GM tile commands to interact with it once converted and loaded?
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).Would you be able to incorporate user defined depth values for tile layers, and the ability to use more than one tileset per map?
Could you be kind enough to give an example of something simple like getting the TileID at the current mouse X/Y?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.
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 doneDepth values for layers are already definable by the user.
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.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
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.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.
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 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.
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.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?
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.Are things going to change much with your planned update?
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.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.
The docs for tile_get_id say:I'm not sure if I understand what you mean here, you shouldn't need to loop through tiles to get the tile id..
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.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.
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 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.
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.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)
You need the code for it to work, using it is quite straightforward, check the privided example (the create code for the rooms).So could I directly import it as a Object or Sprite, or is the code needed for it to work properly?
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.You need the code for it to work, using it is quite straightforward, check the privided example (the create code for the rooms).
Well that's the easiest solution if you only need an image of the map, for bigger maps it's not so good.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.
Linked it for youAnyone 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"
Thanks, it's because I'm new to the forums.(It's the paperclip / chain link looking thing on the toolbar at the top of where you type your text when posting)
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 ?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
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.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 ?