Gamedev Framework (gf)  0.3.0
A C++11 framework for 2D games
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 (Vector2u layerSize)
 Constructor. More...
 
virtual void draw (RenderTarget &target, 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 TexturegetTexture () const
 Get the source texture of the tileset. More...
 
void setTileSize (Vector2u tileSize)
 Set the tile size in the tileset. More...
 
Vector2u getTileSize () const
 Get the tile size in the tileset. More...
 
void setMargin (unsigned margin)
 Set the margin of the tileset. More...
 
void setMargin (Vector2u margin)
 Set the margin of the tileset. More...
 
Vector2u getMargin () const
 Get the margin of the tileset. More...
 
void setSpacing (unsigned spacing)
 Set the spacing of the tileset. More...
 
void setSpacing (Vector2u spacing)
 Set the spacing of the tileset. More...
 
Vector2u getSpacing () const
 Get the spacing of the tileset. More...
 
Tile definition
void setBlockSize (Vector2u blockSize)
 Set the block size. More...
 
Vector2u getBlockSize () const
 Get the block size. More...
 
void setTile (Vector2u position, int tile)
 Set a tile. More...
 
int getTile (Vector2u position) const
 Get 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...
 

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.

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:

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

gf::TileLayer::TileLayer ( Vector2u  layerSize)

Constructor.

Parameters
layerSizethe size of the layer, in number of tiles

Member Function Documentation

void gf::TileLayer::clear ( )

Remove all the tiles.

virtual void gf::TileLayer::draw ( RenderTarget target,
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.

Vector2u gf::TileLayer::getBlockSize ( ) const

Get the block size.

The block size is the size of tiles in the layer. If not specified, it is the same as the tile size.

Returns
The block size
Vector2u gf::TileLayer::getMargin ( ) const
inline

Get the margin of the tileset.

Returns
The margin, in pixels
See also
setMargin()
Vector2u gf::TileLayer::getSpacing ( ) const
inline

Get the spacing of the tileset.

Returns
The spacing, in pixels
See also
setSpacing()
const Texture* gf::TileLayer::getTexture ( ) const
inline

Get the source texture of the tileset.

If the tile layer has no source texture, a nullptr pointer is returned. The returned pointer is const, which means that you can't modify the texture when you retrieve it with this function.

Returns
Pointer to the tileset's texture
See also
setTexture()
int gf::TileLayer::getTile ( Vector2u  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()
Vector2u gf::TileLayer::getTileSize ( ) const
inline

Get the tile size in the tileset.

Returns
The tile size, in pixels
See also
setTileSize()
void gf::TileLayer::setBlockSize ( Vector2u  blockSize)

Set the block size.

The block size is the size of tiles in the layer. If not specified, it is the same as the tile size.

Parameters
blockSizeThe new size of the block, in pixels
See also
getBlockSize()
void gf::TileLayer::setMargin ( unsigned  margin)
inline

Set the margin of the tileset.

Parameters
marginThe margin, in pixels
See also
getMargin()
void gf::TileLayer::setMargin ( Vector2u  margin)

Set the margin of the tileset.

Parameters
marginThe margin, in pixels
See also
getMargin()
void gf::TileLayer::setSpacing ( unsigned  spacing)
inline

Set the spacing of the tileset.

Parameters
spacingThe spacing, in pixels
See also
getSpacing()
void gf::TileLayer::setSpacing ( Vector2u  spacing)

Set the spacing of the tileset.

Parameters
spacingThe spacing, in pixels
See also
getSpacing()
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.

Parameters
textureNew texture
See also
getTexture()
void gf::TileLayer::setTile ( Vector2u  position,
int  tile 
)

Set a tile.

Parameters
positionThe position of the tile in the tile layer
tileThe number of the tile in the tileset or gf::TileLayer::NoTile
See also
getTile()
void gf::TileLayer::setTileSize ( Vector2u  tileSize)

Set the tile size in the tileset.

Parameters
tileSizeThe new tile size, in pixels
See also
getTileSize()

Member Data Documentation

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

A constant meaning that there is no tile.