GetTileName
From Spheriki
Gets the name of a tile, given its index in the tileset.
Contents |
Usage
- tile_index Number, non-negative. The index of the tile to get the name of.
- String is returned, containing the name given to the tile.
Examples
Say we have a tileset that looks like this:
0 = blank image 1 = grass tile image 2 = sand tile image 3 = water tile image 4 = fence tile image
We want to be able to tell what a walking person can travel over. We can put this sort of information inside the tile's name. This can be done in the Sphere IDE's map editor.
0.name = 1.name = land 2.name = land 3.name = fence 4.name = fence
Names are not used by the map engine for any purpose other than holding data for your convenience, so they can be set or just blank, depending on what's convenient for you.
To view the name of the tile that a person is standing on, insert these pieces of code:
/**
* In the main game script file.
*/
var font = GetSystemFont();
var person = "joe";
var spriteset = "hahaha.rss";
var map = "test.rmp";
function main()
{
CreatePerson(person, spriteset, false);
AttachInput(person);
AttachCamera(person);
MapEngine(map);
}
/** * In the map's render script, using the Sphere IDE's map editor. */ var tile_x = Math.round(GetPersonX(person) / GetTileWidth()); var tile_y = Math.round(GetPersonY(person) / GetTileHeight()); ///////////////////////////////////////////////////// var tile_name = GetTileName(GetTile(tile_x, tile_y)); ///////////////////////////////////////////////////// font.drawText(0, 0, "Tile name: " + tile_name);
Now when you run the game, you should see the name of the current tile at the top left of the screen.
Or something simpler:
var tile_name = GetTileName(1);
This should set tile_name to the value "land".
Notes
- Currently, the only way to set the name of a tile is using a map editor.
- Tile names are not used for any purpose by the map engine, which makes them useful for storing little bits of information about tiles.
- This function only makes sense when run within the map engine.
See also
- GetTile()
- GetTileHeight()
- GetTileImage()
- GetTileWidth()
- SetTileImage()
- MapEngine()