# rmp::Tilemap

> A level read from an LDtk or a Tiled file: its tile layers, which cells are solid, and the objects placed in it.

Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html

class `#include <rmp/tilemap.h>` [include/rmp/tilemap.h:137](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L137-L224)

class Tilemap

A level read from an LDtk or a Tiled file: its tile layers, which cells are solid, and the objects placed in it. Every Scene has one in `map`, which [`rmp::assets::load_map()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#load_map) fills; it moves and does not copy.

### `Tilemap`

Tilemap()

function [include/rmp/tilemap.h:142](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L142)

Declared here and defined in tilemap.cpp, all of them: MapData is incomplete in this header, and even a defaulted constructor written here would instantiate the unique_ptr's deleter against it.

### `valid`, `operator bool`

bool valid() const

explicit operator bool() const

function [include/rmp/tilemap.h:155](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L155)

Whether a map is loaded: false for an empty one, and for one whose file was missing or did not parse. Every query below then answers zero, empty or false, and `on_object()` registers nothing.

### `bounds`

Rectangle bounds() const

function [include/rmp/tilemap.h:158](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L158)

In world units

### `tile_size`

Vector2 tile_size() const

function [include/rmp/tilemap.h:159](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L159)

One cell, in world units

### `layer_count`

int layer_count() const

function [include/rmp/tilemap.h:160](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L160)

How many tile layers; 0 is the bottom one

### `object_count`

int object_count() const

function [include/rmp/tilemap.h:161](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L161)

How many MapObjects it holds

## The levels of an LDtk world

### `level`, `neighbour_at`

std::string_view level() const

std::string_view neighbour_at(Vector2 world_position) const

function [include/rmp/tilemap.h:176](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L176)

The level this map is, and the OTHER level of its world at a point — "" while the point is still in this one, or in none. So walking into the next level is

```cpp
const std::string_view next = map.neighbour_at(player.position);
if (!next.empty()) rmp::Scene::change<Level>(std::string(next), player.position);
```

and the new scene loads that level and puts the player back where it was: the coordinates are the world's, so they still mean the same place. Tiled maps and LDtk's linear layouts have no world, and always say "". Views of the parsed map, each followed by a NUL: valid while it is loaded.

## Object layers -> objects in the scene

### `on_object`, `spawn_objects`

void on_object(std::string_view type, Callback<Scene &, const MapObject &> factory)

void spawn_objects(Scene &into)

function [include/rmp/tilemap.h:190](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L190)

A type with no factory registered comes out as a plain [`rmp::Object`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html) with the position, the size and a collider — and `solid` already set WHEN THE EDITOR GAVE IT AN AREA, which is the right default for a wall or a platform drawn in the editor. A point, and anything else whose width or height is zero, is a marker rather than a shape and comes out non-solid: an invisible collider at a spawn point is not what anybody drew.

Registering the same class twice REPLACES, because two factories for one class is never what anybody means.

## Queries, for whatever you want to do yourself

### `tile_at`

int tile_at(int layer, int column, int row) const

function [include/rmp/tilemap.h:198](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L198)

The tile in one cell of one layer, as its global tile id: 0 when the cell is empty, outside the layer, or there is no map. Layers count from 0 in the order the file has them, and the cell is in that layer's own grid. For LDtk it is the topmost tile of the cell.

### `solid_at`

bool solid_at(Vector2 world_position) const

function [include/rmp/tilemap.h:202](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L202)

Whether a solid cell is under a point, in world units, on any layer: an LDtk IntGrid cell painted with `solid`, any tile of a Tiled layer whose class is `solid`, or a tile its tileset marks solid. False with no map.

### `solid_in`

bool solid_in(Rectangle world_rect) const

function [include/rmp/tilemap.h:205](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L205)

Whether a solid cell covers any of the rectangle. Only touching it is not: a box standing on the floor is not in the floor.

### `draw`

void draw() const

void draw(Rectangle area) const

function [include/rmp/tilemap.h:212](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L212)

Drawn by the scene, underneath everything. Here because a game that wants the map somewhere else in its own order can call it. The scene draws only what its camera shows — `draw(area)`, with `area` the world rectangle in view — so a level a hundred screens long costs what one screen costs; `draw()` is every tile.
