Calamity Engine 1.0.0
A cross-platform 2D game engine written in C++ and SDL3.
Loading...
Searching...
No Matches
Tilemap Class Reference

#include <components.hpp>

Inheritance diagram for Tilemap:
Component

Public Member Functions

 Tilemap ()=default
 
 Tilemap (const std::string &texturePath, Vector2 tileSize, std::shared_ptr< Window > window, TextureScaling scaling=TextureScaling::PIXELART)
 
int addTile (const Tile &tile)
 
void removeTile (int index)
 
template<typename... Args>
void addTiles (Args... tiles)
 
void update ()
 
void render (std::shared_ptr< Window >) override
 
void initialize ()
 
void bake ()
 
template<class Archive >
void save (Archive &ar) const
 
template<class Archive >
void load (Archive &ar)
 
- Public Member Functions inherited from Component
virtual ~Component ()=default
 
virtual void update (float deltaTime)
 
virtual void physicsUpdate ()
 
virtual void input (InputEvent &event)
 
virtual void postLoad ()
 
virtual void exit ()
 
NodegetNode () const
 
void setNode (Node *n)
 
template<class Archive >
void save (Archive &ar) const
 
template<class Archive >
void load (Archive &ar)
 

Public Attributes

bool visible = true
 
Texture texture
 
Vector2 tileSize
 
std::vector< Tiletiles
 
std::vector< SDL_Vertex > vertexBuffer
 
std::vector< int > indexBuffer
 

Detailed Description

Tilemap

Using the Tilemap class, you can draw Tiles to the screen. Tiles define a sourceRect, among other things.

Here is a basic example:

std::shared_ptr<Node> node = std::make_shared<Node>("tileNode");
// The tilesize Vector2 in the constructor represents the tile size that is rendered to the screen!
std::shared_ptr<Tilemap> map = std::make_shared<Tilemap>("res://path/to/texture.png", TextureScaling::PIXELART, Vector2{64.0f, 64.0f});
tilemap->addTiles(
Tile(Vector2{-5, 0}, Rect{{0, 0}, {16, 16}}),
Tile(Vector2{-4, 0}, Rect{{0, 0}, {16, 16}}),
Tile(Vector2{-3, 0}, Rect{{0, 0}, {16, 16}}),
Tile(Vector2{-2, 0}, Rect{{0, 0}, {16, 16}}),
Tile(Vector2{-1, 0}, Rect{{0, 0}, {16, 16}}),
Tile(Vector2{0, 0}, Rect{{0, 0}, {16, 16}}),
);
node->addComponent(map);
Definition definitions.hpp:294
Definition definitions.hpp:509
Definition definitions.hpp:77

Make sure to check out the platformer example too! It uses the Tilemap component for its map rendering.

Constructor & Destructor Documentation

◆ Tilemap() [1/2]

Tilemap::Tilemap ( )
default

◆ Tilemap() [2/2]

Tilemap::Tilemap ( const std::string &  texturePath,
Vector2  tileSize,
std::shared_ptr< Window window,
TextureScaling  scaling = TextureScaling::PIXELART 
)

Member Function Documentation

◆ addTile()

int Tilemap::addTile ( const Tile tile)

◆ addTiles()

template<typename... Args>
void Tilemap::addTiles ( Args...  tiles)
inline

◆ bake()

void Tilemap::bake ( )

◆ initialize()

void Tilemap::initialize ( )
inlinevirtual

Reimplemented from Component.

◆ load()

template<class Archive >
void Tilemap::load ( Archive &  ar)
inline

◆ removeTile()

void Tilemap::removeTile ( int  index)

◆ render()

void Tilemap::render ( std::shared_ptr< Window window)
overridevirtual

Reimplemented from Component.

◆ save()

template<class Archive >
void Tilemap::save ( Archive &  ar) const
inline

◆ update()

void Tilemap::update ( )

Member Data Documentation

◆ indexBuffer

std::vector<int> Tilemap::indexBuffer

◆ texture

Texture Tilemap::texture

◆ tiles

std::vector<Tile> Tilemap::tiles

◆ tileSize

Vector2 Tilemap::tileSize

◆ vertexBuffer

std::vector<SDL_Vertex> Tilemap::vertexBuffer

◆ visible

bool Tilemap::visible = true

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