Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
aegis2d::render::TileMapView Class Reference

A TileMap ready to draw: the textures of its tilesets and where each tile is in them. More...

#include <aegis2d/render/tile_map_view.hpp>

Public Member Functions

 TileMapView (const TileMap &map, TextureManager &textures)
 Loads the image of each tileset as a texture, named by its path.
 
void draw (IRenderer &renderer, std::int32_t first_layer=0) const
 Draws every visible tile layer, from the bottom one.
 
void draw_layer (IRenderer &renderer, std::size_t layer, std::int32_t sprite_layer) const
 Draws one layer, if it is a visible tile layer.
 

Detailed Description

A TileMap ready to draw: the textures of its tilesets and where each tile is in them.

Each tile of a tile layer is a sprite, placed as Tiled shows it: in its cell, bottom-left aligned when its tileset's tiles are larger than the cells, shifted by the layer's offset, with the layer's opacity, flipped left to right or top to bottom by the bits of its global id. Hidden layers are not drawn. With a camera on the renderer, only the cells around Camera::visible() are drawn, so a map of any size costs the tiles of one screen; the renderer batches them, one draw call per tileset and layer.

const auto map = render::TileMap::load(core::asset_path("maps/level.tmj"));
const render::TileMapView view{map, textures};
renderer.begin_frame(background);
renderer.set_camera(camera);
view.draw(renderer); // layer i of the map on sprite layer i
... the entities, on sprite layers above the map's ...
A TileMap ready to draw: the textures of its tilesets and where each tile is in them.
Definition tile_map_view.hpp:34
void draw(IRenderer &renderer, std::int32_t first_layer=0) const
Draws every visible tile layer, from the bottom one.
std::filesystem::path asset_path(const std::filesystem::path &relative)
Path of one asset.
static TileMap load(const std::filesystem::path &path)
Reads a map and its external tilesets.

Tiles flipped along their diagonal (rotated in Tiled) are drawn without that flip: sprites do not rotate.

Constructor & Destructor Documentation

◆ TileMapView()

aegis2d::render::TileMapView::TileMapView ( const TileMap &  map,
TextureManager &  textures 
)

Loads the image of each tileset as a texture, named by its path.

Parameters
mapMap to draw; it must outlive the view and keep its layers.
texturesManager that loads the images, each file once.
Exceptions
ImageErrorif an image cannot be read.

Member Function Documentation

◆ draw()

void aegis2d::render::TileMapView::draw ( IRenderer &  renderer,
std::int32_t  first_layer = 0 
) const

Draws every visible tile layer, from the bottom one.

Parameters
rendererRenderer in a frame, with the camera the map is seen through.
first_layerSprite layer of the map's first layer; layer i of the map goes on first_layer + i, so the layers stack as in Tiled.

◆ draw_layer()

void aegis2d::render::TileMapView::draw_layer ( IRenderer &  renderer,
std::size_t  layer,
std::int32_t  sprite_layer 
) const

Draws one layer, if it is a visible tile layer.

Parameters
rendererRenderer in a frame.
layerIndex in TileMap::layers.
sprite_layerSprite layer to draw it on.
Exceptions
std::out_of_rangeif layer is not below the number of layers.

The documentation for this class was generated from the following file: