GetTile
From Spheriki
Returns the tile (by its index in the tileset) at the given x,y position on the given layer.
Contents |
Usage
- x Number, non-negative. The x ordinate (in tiles) for the tile to be returned.
- y Number, non-negative. The y ordinate (in tiles) for the tile to be returned.
- layer Number, non-negative. Index of the layer for the tile to be returned.
Examples
The GetTile command is used to obtain information from the map's tiles. The most commonly used example of this is to determine what tile a person is currently on, and then determine what action to take. This can be used to damage the player, determine what kind of battle the player should get into, etc. Below we give an example.
//get the tile the person is currently on:
var width = GetTileWidth();
var height = GetTileHeight();
var tile = GetTile(
Math.floor(GetPersonX("player")/width),
Math.floor(GetPersonY("player")/height),
GetPersonLayer("player")
);
if (tile == 27)
{
//Here, we assume that the 27th tile in the map's tileset
//is the grass tile. In this case, if the tile the player
//is on a grass tile, we go into a grassland battle, which
//is done by the StartBattle(filename) function, defined
//elsewhere by the programmer.
StartBattle("grassland.rmp");
}
Notes
- If you use this function on a tile coordinate occupied by an animated tile, you will only get the tile from the map's state at load time.
- The valid range of layers that this function will accept is between 0 (inclusive) and GetNumLayers() (exclusive).
- The valid range of the x and y coordinates are between 0 (inclusive) and GetLayerWidth(layer), GetLayerHeight(layer), respectively (exclusive).
- This function will only work while the map engine is running.