On this page
  1. Tilemap
  2. valid, operator bool
  3. bounds
  4. tile_size
  5. layer_count
  6. object_count
  7. The levels of an LDtk world
  8. level, neighbour_at
  9. Object layers -> objects in the scene
  10. on_object, spawn_objects
  11. Queries, for whatever you want to do yourself
  12. tile_at
  13. solid_at
  14. solid_in
  15. draw

rmp::Tilemap

class #include <rmp/tilemap.h> include/rmp/tilemap.h:137
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() fills; it moves and does not copy.

Tilemap

Tilemap()

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

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

In world units

tile_size

Vector2 tile_size() const

One cell, in world units

layer_count

int layer_count() const

How many tile layers; 0 is the bottom one

object_count

int object_count() const

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

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

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)

A type with no factory registered comes out as a plain rmp::Object 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

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

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

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

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.