Jump to content


Photo
* * * * * 1 votes

Using Tiled To Binary Converter files in GameMaker Studio


  • Please log in to reply
10 replies to this topic

#1 witchmaster

witchmaster

    GMC Member

  • GMC Member
  • 44 posts
  • Version:GM:Studio

Posted 28 January 2016 - 01:22 PM

  • Title:  How to use Tiled To Binary Converter files with Gamemaker Studio
  • Description:  This tutorial shows how to use binary files created with my tool "Tiled To Binary Converter" with Gamemaker Studio. This method should also work for large rooms.
  • GM Version: Studio
  • Registered: No
  • File Type: .gmz
  • File Size:  1.2MB
  • File Link:  http://www.gamephase...TiledBinary.gmz
  • Required Extension: -
  • Required DLL: -
  • Tags: tutorial, tiled, help, guide

 

Summary

 

I have created a versatile (and free) converter for Tiled maps that saves binary files of the tile layers and object groups. The tile layers can also be compressed using run length encoding. I also created the necessary scripts for Gamemaker Studio that reads these files to data structures so it's very convenient to use. :)

 

The tool supports all compression types of the tmx file format used by Tiled (uncompressed, base64, gzip and zlib). Also all object types are supported (tile, rectangle, ellipse, polygon and polyline) and custom properties are also included.

 

Read more about and download Tiled To Binary Converter here:

http://www.gamephase...nary-converter/

 

tiled-to-binary-screenshot.png

 

You can save the files directly to the "datafiles" folder in your project folder and add these as "Included files" in GMS. When replacing files you just save over the files with the converter tool, no need to include the files again in GMS.

 

Using the imported data is quite straightforward since data structures (ds_grids, ds_maps and ds_lists), are created when using my scripts. The only scripts you should need to edit to your liking are "create_tile_layers" and "create_objects". You can also entirely skip using those two scripts and use the data structures however you like.

 

Below you can download the Gamemaker Studio scripts and example, the Tiled map I used for the demo and the documentation for the data structures created.

http://www.gamephase...memaker-studio/

 

To use the scripts in your own projects, just import the scripts and call the scripts like below in the room create event (or somewhere else).

// Load the map
global.tile_map = load_map("map.bin");

// Load all the objects from Tiled to a list
global.list_objects = load_object_list("objects.bin", 8); // 8=tilewidth

// Create the tile layers
create_tile_layers(global.tile_map, bg_tiles, 8, 8); // 8=tilewidth,tileheight

// Create the loaded objects
create_objects(global.list_objects);

All the scripts are licensed under Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
http://creativecommo...nses/by-sa/4.0/

 

I hope you find this useful, you should be able to create large rooms by using this method. I'm using a custom drawing technique myself for a room that has 1000x1000 tiles (8000x8000px big), works really well. :)


  • 2

thy-sword-banner-noflash.gif


#2 chance

chance

    GMC Member

  • Global Moderators
  • 8762 posts
  • Version:GM:Studio

Posted 28 January 2016 - 02:46 PM

This is fine for the Tutorials Forum.  The code is properly written and explained.  It's not an example (or tool) for beginners.   But for users who understand the basics of ds_grids, _maps, and _lists, it should be easy to understand and follow.

 

It's great that you've created a tool and offered it to members.  That's a considerable about of work.  That said, it's not immediately clear what benefit it offers over the built-in data conversion features, such as ds_grid_write() and ds_grid_read() when used along with the ini_write and read functions.

 

But your method does allow for compression, which could be an advantage for large projects.   And your example is complete, in the sense that it illustrates how to reconstruct tile layers.  So nice job overall.  +1


  • 1

#3 witchmaster

witchmaster

    GMC Member

  • GMC Member
  • 44 posts
  • Version:GM:Studio

Posted 28 January 2016 - 03:15 PM

Thanks for the add!

 

I could have made the converter write ini-files instead but I wanted binary files since they are not as easy to edit and also reading binary files should be quite simple in other environments. When using the provided scripts you don't need to understand the actual binary files. And also there is the compression thing like you mentioned. :)

 

Anyway, for anybody that wants to use this, I  will be glad to help if you have problems!


Edited by witchmaster, 08 March 2016 - 11:54 AM.

  • 0

#4 Kuhn92

Kuhn92

    GMC Member

  • New Member
  • 3 posts
  • Version:GM:Studio

Posted 05 March 2016 - 02:30 AM

I have a isometric map 128 * 64 and when I convert it to .bin format and try it to open with game maker It open as a Orthogonal map
Sorry for my english I hope that you can understand me and tiles load bad
Regards

  • 0

#5 witchmaster

witchmaster

    GMC Member

  • GMC Member
  • 44 posts
  • Version:GM:Studio

Posted 06 March 2016 - 09:27 AM

 

I have a isometric map 128 * 64 and when I convert it to .bin format and try it to open with game maker It open as a Orthogonal map
Sorry for my english I hope that you can understand me and tiles load bad
Regards

 

 

The example I made for Gamemaker is for orthogonal maps only, you need to modify the create_tile_layers function to make it work with isometric maps.


  • 0

thy-sword-banner-noflash.gif


#6 Kuhn92

Kuhn92

    GMC Member

  • New Member
  • 3 posts
  • Version:GM:Studio

Posted 06 March 2016 - 05:56 PM

I did it look:
global.tile_map = load_map("map_test.bin");

create_tile_layers(global.tile_map, test_tile, 128, 64);

 

I changed this two lines but the problem comes here:
http://imageshack.co...3340/SIEuX6.jpg


  • 0

#7 witchmaster

witchmaster

    GMC Member

  • GMC Member
  • 44 posts
  • Version:GM:Studio

Posted 07 March 2016 - 06:41 AM

I did it look:
global.tile_map = load_map("map_test.bin");

create_tile_layers(global.tile_map, test_tile, 128, 64);

 

I changed this two lines but the problem comes here:
http://imageshack.co...3340/SIEuX6.jpg

 

Ok, you need to change the call to tile_add in the create_tile_layers script. I haven't worked with isometric maps myself but instead of placing tiles from left to right you need to place the tiles diagonally so to say.

for(i = 0; i < layer_count; i++)
{
    grid = list[| i];
    for(ypos = 0; ypos < map_height; ypos++)
    {
        for(xpos = 0; xpos < map_width; xpos++)
        {
            value = grid[# xpos, ypos];
            tile_add(tileset, ((value-1) mod tileset_width)*tile_width, ((value-1) div tileset_width)*tile_height, tile_width, tile_height, xpos*tile_width, ypos*tile_height, depths[i]);
        }
    }
}

Edited by witchmaster, 07 March 2016 - 07:39 AM.

  • 0

thy-sword-banner-noflash.gif


#8 witchmaster

witchmaster

    GMC Member

  • GMC Member
  • 44 posts
  • Version:GM:Studio

Posted 07 March 2016 - 07:38 AM

I did it look:
global.tile_map = load_map("map_test.bin");

create_tile_layers(global.tile_map, test_tile, 128, 64);

 

I changed this two lines but the problem comes here:
http://imageshack.co...3340/SIEuX6.jpg

 

Hey man, I updated the TiledBinary.gmz example so there is now a second room that loads an isometric map. I modified the script create_tile_layers script to work with both orthogonal and isometric maps. Download it again and see how it works, hopefully this will work out for you! :)


Edited by witchmaster, 08 March 2016 - 11:54 AM.

  • 0

#9 Kuhn92

Kuhn92

    GMC Member

  • New Member
  • 3 posts
  • Version:GM:Studio

Posted 07 March 2016 - 02:38 PM

Excellent! Only have one problem but I will try to research about it when I can go to my house
Right now I can load the map but its a little smaller than the original tiles*
 
Here is the Map loaded:  http://imageshack.co...2985/KQIt4N.jpg
 
**I made another map to see what it was happening and I realized that is the " zoom " or at least that is It that i think
When I use Tiled if I zooms out it's seems like GMS but If I zoom in I get a better image.
 
***Yes, It was that.. When I changed the view values, I could get a better image.
Thanks so much!

Edited by Kuhn92, 07 March 2016 - 03:34 PM.

  • 0

#10 Roncon93

Roncon93

    GMC Member

  • New Member
  • 1 posts
  • Version:GM:Studio

Posted 14 March 2016 - 11:24 PM

Hi witchmaster! Great work on the tool. I want to implement precise tile collision into my game, could this be done using your tool?

 

Edit: Let me be more specific. In your demo, I see you used the Insert Tile tool in Tiled to create the hero and enemy objects. I could do something similar to create walls, buildings and other static objects of the like. But is there any way to have a collision system that uses shapes rather than tiles?

 

Also, does your tool support the "Tile Collision Editor" tool for Tiled?


Edited by Roncon93, 14 March 2016 - 11:31 PM.

  • 0

#11 witchmaster

witchmaster

    GMC Member

  • GMC Member
  • 44 posts
  • Version:GM:Studio

Posted 15 March 2016 - 06:21 AM

Hi witchmaster! Great work on the tool. I want to implement precise tile collision into my game, could this be done using your tool?

 

Edit: Let me be more specific. In your demo, I see you used the Insert Tile tool in Tiled to create the hero and enemy objects. I could do something similar to create walls, buildings and other static objects of the like. But is there any way to have a collision system that uses shapes rather than tiles?

 

Also, does your tool support the "Tile Collision Editor" tool for Tiled?

 

You could do something like inserting invisible objects (for collisions) with different sprites depending on the tile numbers, with no objects needed in Tiled. You would do this in the create_tile_layers function in the example. You could make an array with references to sprites so an index in the array corresponds with a tile number in the map, this way it could be quite automatic. You could enable precise collision for only those sprites that need it.

I can't really be of any great help when it comes to other collision systems than the build in ones in Gamemaker, I have so far used invisible objects for "tile" collisions or a tile layer (ds_grid). My export tool does not support the collision editor in Tiled, I may add support for this some day but now all my time goes to "Thy Sword" and other projects.


  • 0

thy-sword-banner-noflash.gif