KcdMp.worldToMap
Where a position in the world lies on the map picture.
map is what KcdMp.mapInfo resolved with; x and y are a position in the world in metres - a player’s
position from your game mode (GetPlayerPos), a building’s, anything. The answer is in the region map’s pixels at its
full size (map.width by map.height): on a picture shown w pixels wide, the place is x * w / map.width. With
town, the answer is on that town’s own picture instead (pictureWidth by pictureHeight), which may lie outside it
when the position is not in the town.
Gives null when map is not a map from KcdMp.mapInfo, a coordinate is not a number, or town is not one of
the map’s towns.
Syntax
Section titled “Syntax”KcdMp.worldToMap(map, x, y, town?)| Parameter | Type | |
|---|---|---|
map |
KcdMpMapInfo |
the level’s map, from KcdMp.mapInfo |
x |
number |
the world position’s x, in metres |
y |
number |
the world position’s y, in metres |
town |
string |
a town’s name from map.towns, for its own picture (optional) |
Returns
Section titled “Returns”KcdMpMapPoint | null - the place on the picture, in its pixels at full size
KcdMpMapPoint
Section titled “KcdMpMapPoint”A point on a map picture or in the world.
| Field | Type | |
|---|---|---|
x |
number |
the point’s x - pixels from the left on a map, metres in the world |
y |
number |
the point’s y - pixels from the top on a map, metres in the world |
Example
Section titled “Example”const info = await KcdMp.mapInfo();const img = document.querySelector("#map"); // KcdMp.mapImage({ width: 1024 })const dot = document.querySelector("#me"); // position: absolute, over the pictureKcdMp.onServer("me.pos", ({ x, y }) => { const p = KcdMp.worldToMap(info, x, y); dot.style.left = (p.x / info.width * 100) + "%"; dot.style.top = (p.y / info.height * 100) + "%";});See also
Section titled “See also”KcdMp.mapToWorld · KcdMp.mapInfo · the The game’s pictures and typefaces group of the index
