FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
fge::TileSet Class Reference

A class that represent a set of tiles that can be used in a TileLayer. More...

#include <C_tileset.hpp>

Public Types

using TileListType = std::set<fge::TileData, std::less<>>
 

Public Member Functions

 TileSet (fge::Texture texture)
 
 TileSet (fge::Texture texture, fge::Vector2i const &tileSize)
 
 TileSet (fge::Texture texture, fge::Vector2i const &tileSize, fge::Vector2i const &offset)
 
void clearTiles ()
 Clear the tiles.
 
void setName (std::string name)
 Set the name of the TileSet.
 
std::string const & getName () const
 Get the name of the TileSet.
 
bool valid () const
 Check if the TileSet have a valid Texture.
 
fge::Texture const & getTexture () const
 Get the texture of the TileSet.
 
void setTexture (fge::Texture texture)
 Set the texture of the TileSet.
 
fge::Vector2i const & getTileSize () const
 Get the tile size of the TileSet.
 
void setTileSize (fge::Vector2i const &tileSize)
 Set the tile size of the TileSet.
 
fge::Vector2i const & getOffset () const
 Get the offset in pixel of the TileSet.
 
void setOffset (fge::Vector2i const &offset)
 Set the offset in pixel of the TileSet.
 
std::size_t getTileCount () const
 Get the total number of tiles in the TileSet.
 
fge::TileData const * getTile (TileId id) const
 Retrieve a tile by its local id.
 
TileId getLocalId (fge::Vector2i const &position) const
 Get the local id of a tile by its grid position.
 
TileId getLocalId (TileId gid) const
 Get the local id of a tile by its global id.
 
bool isGidContained (TileId gid) const
 Check if the global id is in the tileset.
 
void setFirstGid (TileId gid)
 Set the first global id of the tileset.
 
TileId getFirstGid () const
 Get the first global id of the tileset.
 
TileListType::const_iterator begin () const
 
TileListType::const_iterator end () const
 
void slice ()
 Slice the texture into tiles.
 
int getColumns () const
 Return the number of columns in the texture.
 
int getRows () const
 Return the number of rows in the texture.
 
std::optional< fge::RectIntgetTextureRect (TileId id) const
 Get the texture rectangle of a tile by its local id.
 
fge::RectInt computeTextureRect (TileId id) const
 Compute the supposed texture rectangle with a local id.
 
fge::TileSetoperator= (fge::Texture texture)
 

Detailed Description

A class that represent a set of tiles that can be used in a TileLayer.

This class is compatible with the "Tiled" map editor.

Member Function Documentation

◆ clearTiles()

void fge::TileSet::clearTiles ( )

Clear the tiles.

◆ computeTextureRect()

fge::RectInt fge::TileSet::computeTextureRect ( TileId id) const
nodiscard

Compute the supposed texture rectangle with a local id.

Parameters
idThe local id of the tile
Returns
The supposed texture rectangle of the tile

◆ getColumns()

int fge::TileSet::getColumns ( ) const
nodiscard

Return the number of columns in the texture.

Returns
The number of columns in the texture

◆ getFirstGid()

TileId fge::TileSet::getFirstGid ( ) const
nodiscard

Get the first global id of the tileset.

Returns
The first global id of the tileset

◆ getLocalId() [1/2]

TileId fge::TileSet::getLocalId ( fge::Vector2i const & position) const
nodiscard

Get the local id of a tile by its grid position.

Parameters
positionThe grid position of the tile
Returns
The local id of the tile if found, -1 otherwise

◆ getLocalId() [2/2]

TileId fge::TileSet::getLocalId ( TileId gid) const
nodiscard

Get the local id of a tile by its global id.

The global id is subtracted by the first global id of the tileset in order to get the local id.

Parameters
gidThe global id of the tile
Returns
The local id of the tile if found, -1 otherwise

◆ getName()

std::string const & fge::TileSet::getName ( ) const
nodiscard

Get the name of the TileSet.

Returns
The name of the TileSet

◆ getOffset()

fge::Vector2i const & fge::TileSet::getOffset ( ) const
nodiscard

Get the offset in pixel of the TileSet.

Returns
The offset in pixel of the TileSet

◆ getRows()

int fge::TileSet::getRows ( ) const
nodiscard

Return the number of rows in the texture.

Returns
The number of rows in the texture

◆ getTexture()

fge::Texture const & fge::TileSet::getTexture ( ) const
nodiscard

Get the texture of the TileSet.

Returns
The texture of the TileSet

◆ getTextureRect()

std::optional< fge::RectInt > fge::TileSet::getTextureRect ( TileId id) const
nodiscard

Get the texture rectangle of a tile by its local id.

Parameters
idThe local id of the tile
Returns
The texture rectangle of the tile if found, std::nullopt otherwise

◆ getTile()

fge::TileData const * fge::TileSet::getTile ( TileId id) const
nodiscard

Retrieve a tile by its local id.

Parameters
idThe local id of the tile
Returns
The tile pointer if found, nullptr otherwise

◆ getTileCount()

std::size_t fge::TileSet::getTileCount ( ) const
nodiscard

Get the total number of tiles in the TileSet.

Returns
The total number of tiles in the TileSet

◆ getTileSize()

fge::Vector2i const & fge::TileSet::getTileSize ( ) const
nodiscard

Get the tile size of the TileSet.

Returns
The tile size of the TileSet

◆ isGidContained()

bool fge::TileSet::isGidContained ( TileId gid) const
nodiscard

Check if the global id is in the tileset.

Parameters
gidThe global id of the tile
Returns
true if the global id is in the tileset, false otherwise

◆ setFirstGid()

void fge::TileSet::setFirstGid ( TileId gid)

Set the first global id of the tileset.

The first global id correspond to the first tile id in the tileset.

Parameters
gidThe first global id of the tileset

◆ setName()

void fge::TileSet::setName ( std::string name)

Set the name of the TileSet.

Parameters
nameThe name of the TileSet

◆ setOffset()

void fge::TileSet::setOffset ( fge::Vector2i const & offset)

Set the offset in pixel of the TileSet.

Parameters
offsetThe offset in pixel of the TileSet

◆ setTexture()

void fge::TileSet::setTexture ( fge::Texture texture)

Set the texture of the TileSet.

This function will automatically slice the texture into tiles.

Parameters
textureThe texture of the TileSet

◆ setTileSize()

void fge::TileSet::setTileSize ( fge::Vector2i const & tileSize)

Set the tile size of the TileSet.

This function will automatically slice the texture into tiles.

Parameters
tileSizeThe tile size of the TileSet

◆ slice()

void fge::TileSet::slice ( )

Slice the texture into tiles.

The texture will be sliced into tiles of the size specified by the tile size. Tiles is always sliced from the top left corner of the texture in a Z pattern.

Previous tiles will be cleared.

◆ valid()

bool fge::TileSet::valid ( ) const
nodiscard

Check if the TileSet have a valid Texture.

Returns
true if the TileSet have a valid Texture, false otherwise

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