Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
gf::TileLayer Class Reference

A tile layer. More...

#include <gf/TileLayer.h>

Inheritance diagram for gf::TileLayer:
Inheritance graph
[legend]

Public Member Functions

 TileLayer ()
 Constructor. More...
 
Vector2i getMapSize () const
 Get the size of the layer. More...
 
RectF getLocalBounds () const
 Get the local bounding rectangle of the layer. More...
 
void setAnchor (Anchor anchor)
 Set the anchor origin of the entity. More...
 
VertexBuffer commitGeometry () const
 Create a buffer with the current geometry. More...
 
virtual void draw (RenderTarget &target, const RenderStates &states) override
 Draw the object to a render target. More...
 
Tileset parameters
std::size_t createTilesetId ()
 Create a tileset id. More...
 
TilesetgetTileset (std::size_t id)
 Get a tileset with a tileset id. More...
 
const TilesetgetTileset (std::size_t id) const
 Get a tileset with a tileset id. More...
 
void setTilesetSmooth (bool smooth=true)
 Enable or disable the smooth filter on the texture of tilesets. More...
 
Tile definition
void setTile (Vector2i position, std::size_t tileset, int tile, Flags< Flip > flip=None)
 Set a tile. More...
 
int getTile (Vector2i position) const
 Get a tile. More...
 
Flags< FlipgetFlip (Vector2i position) const
 Get the flip properties of a tile. More...
 
std::size_t getTileTileset (Vector2i position) const
 Get the tileset property of a tile. More...
 
void clear ()
 Remove all the tiles. More...
 
- Public Member Functions inherited from gf::Transformable
 Transformable ()
 Default constructor. More...
 
void setOrigin (Vector2f origin)
 Set the local origin of the object. More...
 
Vector2f getOrigin () const
 Get the local origin of the object. More...
 
void setPosition (Vector2f position)
 Set the position of the object. More...
 
Vector2f getPosition () const
 Get the position of the object. More...
 
void move (Vector2f offset)
 Move the object by a given offset. More...
 
void setRotation (float angle)
 Set the orientation of the object. More...
 
float getRotation () const
 Get the orientation of the object. More...
 
void rotate (float angle)
 Rotate the object. More...
 
void setScale (Vector2f factors)
 Set the scale factors of the object. More...
 
void setScale (float factor)
 Set the scale factor of the object. More...
 
Vector2f getScale () const
 Get the current scale of the object. More...
 
void scale (Vector2f factors)
 Scale the object. More...
 
void scale (float factor)
 Scale the object. More...
 
Matrix3f getTransform () const
 Get the combined transform of the object. More...
 
Matrix3f getInverseTransform () const
 Get the inverse of the combined transform of the object. More...
 
- Public Member Functions inherited from gf::Drawable
virtual ~Drawable ()
 Virtual desctructor. More...
 
virtual void draw (RenderTarget &target, const RenderStates &states)=0
 Draw the object to a render target. More...
 

Static Public Member Functions

static TileLayer createOrthogonal (Vector2i layerSize, Vector2i tileSize)
 Create an orthogonal tile layer. More...
 
static TileLayer createStaggered (Vector2i layerSize, Vector2i tileSize, CellAxis axis, CellIndex index)
 Create a staggered tile layer. More...
 
static TileLayer createHexagonal (Vector2i layerSize, Vector2i tileSize, int sideLength, CellAxis axis, CellIndex index)
 Create a hexagonal tile layer. More...
 

Static Public Attributes

static constexpr int NoTile = -1
 A constant meaning that there is no tile. More...
 

Additional Inherited Members

- Protected Member Functions inherited from gf::Transformable
void setOriginFromAnchorAndBounds (Anchor anchor, const RectF &bounds)
 Set the origin from an anchor and bounds. More...
 

Detailed Description

A tile layer.

A tile layer represents a map made of tiles. gf::TileLayer makes it easy to draw a tile map.

The tile layer is given with an array of indices. Each index correspond to a tile in the tileset. Tile 0 correspond to the tile at the top left in the tileset. Then tile are numbered from left to right, and then from top to bottom. If a tile is not present in the tile layer, the constant gf::TileLayer::NoTile can be used.

Constructor & Destructor Documentation

◆ TileLayer()

gf::TileLayer::TileLayer ( )

Constructor.

Member Function Documentation

◆ clear()

void gf::TileLayer::clear ( )

Remove all the tiles.

◆ commitGeometry()

VertexBuffer gf::TileLayer::commitGeometry ( ) const

Create a buffer with the current geometry.

The geometry is uploaded in the graphics memory so that it's faster to draw.

Returns
A buffer with the current geometry

◆ createHexagonal()

static TileLayer gf::TileLayer::createHexagonal ( Vector2i  layerSize,
Vector2i  tileSize,
int  sideLength,
CellAxis  axis,
CellIndex  index 
)
static

Create a hexagonal tile layer.

Parameters
layerSizeThe size of the layer
tileSizeThe size of a tile
sideLengthThe side length
axisThe cells axis
indexThe cells index

◆ createOrthogonal()

static TileLayer gf::TileLayer::createOrthogonal ( Vector2i  layerSize,
Vector2i  tileSize 
)
static

Create an orthogonal tile layer.

Parameters
layerSizeThe size of the layer
tileSizeThe size of a tile

◆ createStaggered()

static TileLayer gf::TileLayer::createStaggered ( Vector2i  layerSize,
Vector2i  tileSize,
CellAxis  axis,
CellIndex  index 
)
static

Create a staggered tile layer.

Parameters
layerSizeThe size of the layer
tileSizeThe size of a tile
axisThe cells axis
indexThe cells index

◆ createTilesetId()

std::size_t gf::TileLayer::createTilesetId ( )

Create a tileset id.

Returns
A new tileset id

◆ draw()

virtual void gf::TileLayer::draw ( RenderTarget target,
const RenderStates states 
)
overridevirtual

Draw the object to a render target.

This is a pure virtual function that has to be implemented by the derived class to define how the drawable should be drawn.

Parameters
targetRender target to draw to
statesCurrent render states

Implements gf::Drawable.

◆ getFlip()

Flags< Flip > gf::TileLayer::getFlip ( Vector2i  position) const

Get the flip properties of a tile.

Parameters
positionThe position of the tile in the tile layer
Returns
A flag to indicate how the tile is flipped
See also
setTile()

◆ getLocalBounds()

RectF gf::TileLayer::getLocalBounds ( ) const

Get the local bounding rectangle of the layer.

The returned rectangle is in local coordinates, which means that it ignores the transformations (translation, rotation, scale, ...) that are applied to the entity. In other words, this function returns the bounds of the entity in the entity's coordinate system.

Returns
Local bounding rectangle of the entity

◆ getMapSize()

Vector2i gf::TileLayer::getMapSize ( ) const
inline

Get the size of the layer.

Returns
The size of the layer, in number of tiles

◆ getTile()

int gf::TileLayer::getTile ( Vector2i  position) const

Get a tile.

Parameters
positionThe position of the tile in the tile layer
Returns
The number of the tile in the tileset or gf::TileLayer::NoTile
See also
setTile()

◆ getTileset() [1/2]

Tileset & gf::TileLayer::getTileset ( std::size_t  id)

Get a tileset with a tileset id.

Parameters
idA valid tileset id
Returns
A reference to the tileset

◆ getTileset() [2/2]

const Tileset & gf::TileLayer::getTileset ( std::size_t  id) const

Get a tileset with a tileset id.

Parameters
idA valid tileset id
Returns
A reference to the tileset

◆ getTileTileset()

std::size_t gf::TileLayer::getTileTileset ( Vector2i  position) const

Get the tileset property of a tile.

Parameters
positionThe position of the tile in the tile layer
Returns
The tileset id of the tile
See also
setTile()

◆ setAnchor()

void gf::TileLayer::setAnchor ( Anchor  anchor)

Set the anchor origin of the entity.

Compute the origin of the entity based on the local bounds and the specified anchor. Internally, this function calls Transformable::setOrigin().

Parameters
anchorThe anchor of the entity
See also
getLocalBounds(), Transformable::setOrigin()

◆ setTile()

void gf::TileLayer::setTile ( Vector2i  position,
std::size_t  tileset,
int  tile,
Flags< Flip flip = None 
)

Set a tile.

Parameters
positionThe position of the tile in the tile layer
tilesetThe tileset id of the tile
tileThe number of the tile in the tileset or gf::TileLayer::NoTile
flipThe flip property of the tile
See also
getTile(), getFlip(), getTileTileset()

◆ setTilesetSmooth()

void gf::TileLayer::setTilesetSmooth ( bool  smooth = true)

Enable or disable the smooth filter on the texture of tilesets.

Parameters
smoothTrue to enable smoothing, false to disable it
See also
Tileset::setSmooth()

Member Data Documentation

◆ NoTile

constexpr int gf::TileLayer::NoTile = -1
staticconstexpr

A constant meaning that there is no tile.