Skip to content

Instantly share code, notes, and snippets.

@ColtonPhillips
Created August 26, 2014 08:09
Show Gist options
  • Save ColtonPhillips/2aed23946c4245b2ab3c to your computer and use it in GitHub Desktop.
Save ColtonPhillips/2aed23946c4245b2ab3c to your computer and use it in GitHub Desktop.
Load a Tiled JSON file into GML and make them tiles in the game. This took me so fricking long.
var tilesize = 16;
var _string = included_file_to_string("/test.json");
var result = json_decode(_string);
var height = ds_map_find_value(result,"height");
var width = ds_map_find_value(result,"width");
var tilesets_list = ds_map_find_value(result,"tilesets");
tilesets_map = ds_list_find_value(tilesets_list,0);
var image_width = ds_map_find_value(tilesets_map,"imagewidth") / tilesize;
var image_height = ds_map_find_value(tilesets_map,"imageheight") / tilesize;
var data_list = ds_map_find_value(result,"data");
var d = 0;
for (var i = 0; i < height; i++) {
for (var j = 0; j < width; j++) {
var _tile_num = ds_list_find_value(data_list,d);
if (_tile_num != 0) {
var _left = ((_tile_num mod image_width)-1)*tilesize;
var _top = (_tile_num div image_width)*tilesize;
tile_add(bg_277,_left,_top,tilesize,tilesize,j*tilesize,i*tilesize,0);
}
d++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment