Skip to content

KcdMp.mapToWorld

Where a place on the map picture lies in the world.

The other way of KcdMp.worldToMap: x and y are a place on the region map in its pixels at full size (or on a town’s picture, with town), and the answer is the world position in metres - for a page where the player clicks the map to set a waypoint, for example, which the page then sends to your game mode. The height is not part of a map: the game mode finds the ground’s.

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.

KcdMp.mapToWorld(map, x, y, town?)
Parameter Type
map KcdMpMapInfo the level’s map, from KcdMp.mapInfo
x number the place’s x on the picture, in its pixels at full size
y number the place’s y on the picture, in its pixels at full size
town string a town’s name from map.towns, when the place is on its picture (optional)

KcdMpMapPoint | null - the world position, in metres

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
const info = await KcdMp.mapInfo();
const img = document.querySelector("#map");
img.addEventListener("click", (event) => {
const box = img.getBoundingClientRect();
const x = (event.clientX - box.left) / box.width * info.width;
const y = (event.clientY - box.top) / box.height * info.height;
const world = KcdMp.mapToWorld(info, x, y);
KcdMp.emitServer("map.waypoint", world);
});

KcdMp.worldToMap · KcdMp.mapInfo · the The game’s pictures and typefaces group of the index