Gamedev Framework (gf)  0.17.0
A C++14 framework for 2D games
Public Member Functions | List of all members
gf::Tileset Class Reference

A tileset. More...

#include <gf/Tileset.h>

Public Member Functions

 Tileset ()
 
void setTexture (const Texture &texture)
 Change the source texture of the tileset. More...
 
const TexturegetTexture () 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 setTileSize (Vector2i tileSize)
 Set the tile size in the tileset. More...
 
Vector2i getTileSize () 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...
 
Vector2i getSize () const
 Get the size of the tileset. More...
 
RectF computeTextureCoords (int tile) const
 Get the texture coordinates for a tile. More...
 
RectF computeTextureCoords (Vector2i coords) const
 Get the texture coordinates for a tile. More...
 

Detailed Description

A tileset.

See also
gf::TileLayer

Constructor & Destructor Documentation

◆ Tileset()

gf::Tileset::Tileset ( )

Member Function Documentation

◆ computeTextureCoords() [1/2]

RectF gf::Tileset::computeTextureCoords ( int  tile) const

Get the texture coordinates for a tile.

Parameters
tileThe tile number
Returns
The texture coordinates

◆ computeTextureCoords() [2/2]

RectF gf::Tileset::computeTextureCoords ( Vector2i  coords) const

Get the texture coordinates for a tile.

Parameters
coordsThe tile coordinates
Returns
The texture coordinates

◆ getMargin()

Vector2i gf::Tileset::getMargin ( ) const
inline

Get the margin of the tileset.

Returns
The margin, in pixels
See also
setMargin()

◆ getOffset()

Vector2i gf::Tileset::getOffset ( ) const
inline

Get the offset of the tileset.

Returns
The offset, in pixels
See also
setOffset()

◆ getSize()

Vector2i gf::Tileset::getSize ( ) const
inline

Get the size of the tileset.

Returns
The size of the tileset in number of tiles

◆ getSpacing()

Vector2i gf::Tileset::getSpacing ( ) const
inline

Get the spacing of the tileset.

Returns
The spacing, in pixels
See also
setSpacing()

◆ getTexture()

const Texture& gf::Tileset::getTexture ( ) const
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.

Returns
Reference to the tileset's texture
See also
setTexture()

◆ getTileSize()

Vector2i gf::Tileset::getTileSize ( ) const
inline

Get the tile size in the tileset.

Returns
The tile size, in pixels
See also
setTileSize()

◆ hasTexture()

bool gf::Tileset::hasTexture ( ) const
inline

Check if a texture is set.

Returns
True if a texture is already set
See also
setTexture(), getTexture()

◆ setMargin() [1/2]

void gf::Tileset::setMargin ( int  margin)
inline

Set the margin of the tileset.

Parameters
marginThe margin, in pixels
See also
getMargin()

◆ setMargin() [2/2]

void gf::Tileset::setMargin ( Vector2i  margin)

Set the margin of the tileset.

Parameters
marginThe margin, in pixels
See also
getMargin()

◆ setOffset()

void gf::Tileset::setOffset ( Vector2i  offset)

Set the offset of the tileset.

Parameters
offsetThe offset, in pixels
See also
getOffset();

◆ setSpacing() [1/2]

void gf::Tileset::setSpacing ( int  spacing)
inline

Set the spacing of the tileset.

Parameters
spacingThe spacing, in pixels
See also
getSpacing()

◆ setSpacing() [2/2]

void gf::Tileset::setSpacing ( Vector2i  spacing)

Set the spacing of the tileset.

Parameters
spacingThe spacing, in pixels
See also
getSpacing()

◆ setTexture()

void gf::Tileset::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()

◆ setTileSize()

void gf::Tileset::setTileSize ( Vector2i  tileSize)

Set the tile size in the tileset.

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

◆ unsetTexture()

void gf::Tileset::unsetTexture ( )

Unset the source texture of the tile layer.

After a call to this function, the tile layer has no source texture.

See also
setTexture()