![]() |
Gamedev Framework (gf)
0.16.0
A C++14 framework for 2D games
|
A tile layer. More...
#include <gf/TileLayer.h>
Public Member Functions | |
TileLayer () | |
Constructor. More... | |
TileLayer (Vector2i layerSize, TileOrientation orientation=TileOrientation::Orthogonal) | |
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 | |
void | setTexture (const Texture &texture) |
Change the source texture of the tileset. More... | |
const Texture & | getTexture () const |
Get the source texture of the tileset. More... | |
bool | hasTexture () const |
Check if a texture is set. More... | |
void | unsetTexture () |
Unset the source texture of the tile layer. More... | |
void | setTilesetTileSize (Vector2i tileSize) |
Set the tile size in the tileset. More... | |
Vector2i | getTilesetTileSize () const |
Get the tile size in the tileset. More... | |
void | setMargin (int margin) |
Set the margin of the tileset. More... | |
void | setMargin (Vector2i margin) |
Set the margin of the tileset. More... | |
Vector2i | getMargin () const |
Get the margin of the tileset. More... | |
void | setSpacing (int spacing) |
Set the spacing of the tileset. More... | |
void | setSpacing (Vector2i spacing) |
Set the spacing of the tileset. More... | |
Vector2i | getSpacing () const |
Get the spacing of the tileset. More... | |
void | setOffset (Vector2i offset) |
Set the offset of the tileset. More... | |
Vector2i | getOffset () const |
Get the offset of the tileset. More... | |
Tile definition | |
void | setTileSize (Vector2i tileSize) |
Set the tile size. More... | |
Vector2i | getTileSize () const |
Get the tile size. More... | |
void | setTile (Vector2i position, int tile, Flags< Flip > flip=None) |
Set a tile. More... | |
int | getTile (Vector2i position) const |
Get a tile. More... | |
Flags< Flip > | getFlip (Vector2i position) const |
Get the flip properties of a tile. More... | |
void | clear () |
Remove all the tiles. More... | |
![]() | |
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... | |
![]() | |
virtual | ~Drawable () |
Virtual desctructor. More... | |
Static Public Attributes | |
static constexpr int | NoTile = -1 |
A constant meaning that there is no tile. More... | |
Additional Inherited Members | |
![]() | |
void | setOriginFromAnchorAndBounds (Anchor anchor, const RectF &bounds) |
Set the origin from an anchor and bounds. More... | |
A tile layer.
A tile layer represents a map made of tiles. gf::TileLayer makes it easy to draw a tile map.
A tile layer is associated to a single tileset. A tileset is a texture that contains all the tiles, ordered in a grid. The tileset has several parameters that are inspired by the parameters in Tiled:
setTilesetTileSize()
, getTilesetTileSize()
)setMargin()
, getMargin()
), default: \( (0,0) \)setSpacing()
, getSpacing()
), default: \( (0,0) \)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.
gf::TileLayer::TileLayer | ( | ) |
Constructor.
gf::TileLayer::TileLayer | ( | Vector2i | layerSize, |
TileOrientation | orientation = TileOrientation::Orthogonal |
||
) |
Constructor.
layerSize | The size of the layer, in number of tiles |
orientation | The orientation of the layer |
void gf::TileLayer::clear | ( | ) |
Remove all the tiles.
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.
|
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.
target | Render target to draw to |
states | Current render states |
Implements gf::Drawable.
Get the flip properties of a tile.
position | The position of the tile in the tile layer |
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.
|
inline |
Get the size of the layer.
|
inline |
|
inline |
|
inline |
|
inline |
Get the source texture of the tileset.
The returned reference is const, which means that you can't modify the texture when you retrieve it with this function.
int gf::TileLayer::getTile | ( | Vector2i | position | ) | const |
Get a tile.
position | The position of the tile in the tile layer |
gf::TileLayer::NoTile
|
inline |
|
inline |
|
inline |
Check if a texture is set.
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()
.
anchor | The anchor of the entity |
|
inline |
void gf::TileLayer::setMargin | ( | Vector2i | margin | ) |
void gf::TileLayer::setOffset | ( | Vector2i | offset | ) |
|
inline |
void gf::TileLayer::setSpacing | ( | Vector2i | spacing | ) |
void gf::TileLayer::setTexture | ( | const Texture & | texture | ) |
Change the source texture of the tileset.
The texture must exist as long as the tile layer uses it. Indeed, the tile layer doesn't store its own copy of the texture, but rather keeps a pointer to the one that you passed to this function. If the source texture is destroyed and the tile layer tries to use it, the behavior is undefined.
texture | New texture |
Set a tile.
position | The position of the tile in the tile layer |
tile | The number of the tile in the tileset or gf::TileLayer::NoTile |
flip | The flip property of the tile |
void gf::TileLayer::setTilesetTileSize | ( | Vector2i | tileSize | ) |
Set the tile size in the tileset.
tileSize | The new tile size, in pixels |
void gf::TileLayer::setTileSize | ( | Vector2i | tileSize | ) |
void gf::TileLayer::unsetTexture | ( | ) |
Unset the source texture of the tile layer.
After a call to this function, the tile layer has no source texture.
|
static |
A constant meaning that there is no tile.