ScreenToMapX
From Spheriki
Converts a screen X coordinate to a map X coordinate.
Contents |
[edit]
Usage
number ScreenToMapX(layer, x);
- layer Number, non-negative. The index of the map layer to convert the screen X coordinate to.
- x Number. The screen X coordinate to change into a map X coordinate.
- number is returned, holding the final map X coordinate.
[edit]
Examples
One potential use for this function (along with ScreenToMapY()) is to change mouse coordinates into map coordinates for picking tiles.
/** In a script file. */ var font = GetSystemFont();
/** In a render script. */
var x = ScreenToMapX(0, GetMouseX());
var y = ScreenToMapY(0, GetMouseY());
var tx = Math.floor(x / GetTileWidth());
var ty = Math.floor(y / GetTileHeight());
var tile = GetTile(tx, ty, 0);
// Display info
font.drawText(0, 0, "(" + x + ", " + y + ") points to tile #" + tile);
The above will show the tile underneath the mouse pointer while the map engine is running.
[edit]
Notes
- This function only operates correctly while the map engine is running.
[edit]
See also
- Font.drawText()
- GetMouseX()
- GetMouseY()
- GetSystemFont()
- GetTile()
- GetTileWidth()
- GetTileHeight()

