Code snippet for Tiled tilesets to AGK
This is a code snippet that creates a file that can be used for tilesets, created in the AGK expected format for tilesets. I will write a full tutorial on how to use this code in a future post. See this post on use of the snippet.
//Change these values if your tiles are a different size in pixels tileWidth = 128 tileHeight = tileWidth numHorizontalTiles = 16 numVerticalTiles = 16 //Open a new file to write. I found no success writing to .txt. fileid = OpenToWrite ( "myfile" ) //Variables used in the loop. string$ = "" //This will be what gets written to the file. tileid=0 //Used to count up and assign each tile an ID //This is the same as saying for(int i=0;i<numHorizontalTiles;i++) with the i++ at the end of loop. i=0 //Start at 0 While i<numHorizontalTiles //Same as above, nested for loops. j=0 //Start at 0 after each loop. While j<numVerticalTiles //increment tileid each loop. In Tiled 0 is no tile, so we start with 1. tileid = tileid + 1 //Assign the line to be written to string$ string$ = Str(tileid) + ":" + Str(j*tileWidth) + ":" + Str(i*tileHeight) + ":" + Str(tileWidth) + ":" + Str(tileHeight) //Write string$ to file. WriteToLine saves it in ASCII readable format. WriteLine(fileid, string$) /* Remove to watch progress. Print(string$) Print(GetWritePath()) Sync() */ //Remove to watch progress. //j++ for the loop j = j + 1 EndWhile //i++ for the loop i = i + 1 EndWhile //Close the file CloseFile ( fileid )