![]() |
Tile functions
A group of functions I've made that can be quite useful when working with tiles. These are mainly for translating level data to tile data to image data(pics1) and back and forth to any degree. For example, if you wish to make your own level editor you will have to parse the .NW format, which uses base64 into tile data. Then you'll have to make that tile data into pixel data, to draw the tile images..
I realize there are already some base64 functions in GS2, but I couldn't seem to get them to work for the .NW tile format, so I made my own. Anyways, the functions and how to use them: TilesToImage(tile) - Converts a tile into pixel position on pics1. Should work for all other tileset types as well. This also supports and returns arrays of tiles like so: TilesToImage({tile1,tile2,tile3,tile4}) So you could use it like so: temp.pixeldata = TilesToImage(681); temp.pixeldata = TilesToImage({681,682,697,698}); Which would return the pixel coordinates of the chair tiles. ImageToTile(pixelX,pixelY) - Converts the pixel position of a tileset image into a tile number. Does NOT support multiple entries. Works like so: temp.chairtile = ImageToTile(400,160); Returns 681, which is the upper-left chair tile of the pics1 indoor chair. Base64ToTile(base64string) Base64ToTile({base64,base64,base64,base64}) Converts .NW base64 data into tile data. Also supports multiple entries like TilesToImage(). temp.chairtile = Base64ToTile("Kp"); temp.chairtile = Base64ToTile({"Kp","Kq","K5","K6"}); First will return 681, and the second will return {681,682,697,698}. TileToBase64(tile) TileToBase64({tile1,tile2,tile3,tile4}) This one will convert tile data into base64 strings, compatible with the .NW format. Examples: temp.chairtile = Base64ToTile(681); returns "Kp" temp.chairtile = Base64ToTile({681,682,697,698}); returns {"Kp","Kq","K5","K6"} PHP Code:
|
Nice collection there, useful.
|
I'm not a fan of differing return types like you've used— I find it better to always return an array in cases like that and simply use returnValue[0] if you only gave it one parameter.
Either way, nice collection as Downsider said :). |
| All times are GMT +2. The time now is 11:01 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.