Tileson 1.4.0
A helpful json parser for Tiled maps
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
tson::Tile Class Reference

#include <Tile.hpp>

Public Member Functions

 Tile ()=default
 
 Tile (IJson &json, tson::Tileset *tileset, tson::Map *map)
 
 Tile (uint32_t id, tson::Tileset *tileset, tson::Map *map)
 
 Tile (uint32_t id, tson::Map *map)
 
bool parse (IJson &json, tson::Tileset *tileset, tson::Map *map)
 
bool parseId (IJson &json)
 
uint32_t getId () const
 
const fs::path & getImage () const
 
const Vector2igetImageSize () const
 
const std::string & getType () const
 
const std::string & getClassType () const
 
tson::TiledClassgetClass ()
 
tson::AnimationgetAnimation ()
 
LayergetObjectgroup ()
 
PropertyCollectiongetProperties ()
 
const std::vector< int > & getTerrain () const
 
template<typename T >
get (const std::string &name)
 
tson::PropertygetProp (const std::string &name)
 
void setProperties (const tson::PropertyCollection &properties)
 
tson::TilesetgetTileset () const
 
tson::MapgetMap () const
 
const tson::RectgetDrawingRect () const
 
const RectgetSubRectangle () const
 
const tson::Vector2f getPosition (const std::tuple< int, int > &tileDataPos)
 
const tson::Vector2i getPositionInTileUnits (const std::tuple< int, int > &tileDataPos)
 
const tson::Vector2i getTileSize () const
 
TileFlipFlags getFlipFlags () const
 
bool hasFlipFlags (TileFlipFlags flags)
 
uint32_t getGid () const
 
void addTilesetAndPerformCalculations (tson::Tileset *tileset)
 

Friends

class Layer
 

Constructor & Destructor Documentation

◆ Tile() [1/4]

tson::Tile::Tile ( )
inlinedefault

◆ Tile() [2/4]

tson::Tile::Tile ( IJson json,
tson::Tileset tileset,
tson::Map map 
)
inline

◆ Tile() [3/4]

tson::Tile::Tile ( uint32_t  id,
tson::Tileset tileset,
tson::Map map 
)
inline

Used in cases where you have a tile without any property

Parameters
id

◆ Tile() [4/4]

tson::Tile::Tile ( uint32_t  id,
tson::Map map 
)
inline

Used in cases where you have a FLIP FLAGGED tile

Parameters
id

Member Function Documentation

◆ addTilesetAndPerformCalculations()

void tson::Tile::addTilesetAndPerformCalculations ( tson::Tileset tileset)
inline

For flip flagged tiles, tilesets must be resolved later.

Parameters
tileset

◆ get()

template<typename T >
T tson::Tile::get ( const std::string &  name)
inline

A shortcut for getting a property. Alternative to getProperties().getValue<T>("<name>")

Template Parameters
TThe template value
Parameters
nameName of the property
Returns
The actual value, if it exists. Otherwise: The default value of the type.

◆ getAnimation()

tson::Animation & tson::Tile::getAnimation ( )
inline

Declared in tileson_forward.hpp

'animation': Array of Frames

Returns

◆ getClass()

tson::TiledClass * tson::Tile::getClass ( )
inline

Gets the class information for the 'type'/'class' This may only give a valid result if the map is loaded through a tson::Project

Returns
a tson::TiledClass object if related map was loaded through tson::Project

◆ getClassType()

const std::string & tson::Tile::getClassType ( ) const
inline

'class': String assigned to class field in editor (optional) This was renamed from 'type' to 'class' in Tiled v1.9

Returns

◆ getDrawingRect()

const tson::Rect & tson::Tile::getDrawingRect ( ) const
inline

Get the information needed to draw the Tile based on its current tileset

Returns
a tson::Rect containing the information needed to draw the tile.

◆ getFlipFlags()

tson::TileFlipFlags tson::Tile::getFlipFlags ( ) const
inline

Declared in tileson_forward.hpp

◆ getGid()

uint32_t tson::Tile::getGid ( ) const
inline

◆ getId()

uint32_t tson::Tile::getId ( ) const
inline

'id': Local ID of the tile

Returns

◆ getImage()

const fs::path & tson::Tile::getImage ( ) const
inline

'image': Image representing this tile (optional)

Returns

◆ getImageSize()

const tson::Vector2i & tson::Tile::getImageSize ( ) const
inline

x = 'imagewidth' and y = 'imageheight': in pixels

Returns

◆ getMap()

tson::Map * tson::Tile::getMap ( ) const
inline

Used for getting the tson::Map who is the parent of this Tile.

Returns
a pointer to the tson::Map where this tile is contained.

◆ getObjectgroup()

tson::Layer & tson::Tile::getObjectgroup ( )
inline

'objectgroup': Layer with type objectgroup (optional)

Returns

◆ getPosition()

const tson::Vector2f tson::Tile::getPosition ( const std::tuple< int, int > &  tileDataPos)
inline

Get the position of the tile in pixels based on the tile data position from the current layer.

Returns
The position of the tile in Pixels

◆ getPositionInTileUnits()

const tson::Vector2i tson::Tile::getPositionInTileUnits ( const std::tuple< int, int > &  tileDataPos)
inline

Helper function.

Get the position of the tile in tile units. The size of each unit is determined by the tile size property of the map. Example: If the tile size is 16x16 in the map, a tile unit of [2, 4] would be [32, 64] in pixels. If you want the position in pixels: use getPosition() instead.

Returns
Position of tile in tile units.

◆ getProp()

tson::Property * tson::Tile::getProp ( const std::string &  name)
inline

Shortcut for getting a property object. Alternative to getProperties().getProperty("<name>");

Parameters
nameName of the property
Returns

◆ getProperties()

tson::PropertyCollection & tson::Tile::getProperties ( )
inline

'properties': A list of properties (name, value, type).

Returns

◆ getSubRectangle()

const tson::Rect & tson::Tile::getSubRectangle ( ) const
inline

Tiled 1.9: Contains the newly added sub-rectangle variables: 'x', 'y', 'width' and 'height'

Returns
A tson::Rect with the 'x', 'y', 'width' and 'height' values

◆ getTerrain()

const std::vector< int > & tson::Tile::getTerrain ( ) const
inline

'terrain': Index of terrain for each corner of tile

Returns

◆ getTileset()

tson::Tileset * tson::Tile::getTileset ( ) const
inline

Used for getting the tson::Tileset who is the parent of this Tile.

Returns
a pointer to the tson::Tileset where this tile is contained.

◆ getTileSize()

const tson::Vector2i tson::Tile::getTileSize ( ) const
inline

Really just a shortcut to retrieve the tile size from the map.

Returns
TileSize based on the map property for tile size.

◆ getType()

const std::string & tson::Tile::getType ( ) const
inline

'type': The type of the tile (optional) This was renamed to 'class' in Tiled v1.9

Returns

◆ hasFlipFlags()

bool tson::Tile::hasFlipFlags ( tson::TileFlipFlags  flags)
inline
Parameters
flagsWhich flags to check for. Several flags can be checked at once using the bitwise or operator. Example: hasFlipFlags(TileFlipFlags::Vertically | TileFlipFlags::Horizontally)
Returns
true if the flag(s) specified are set

◆ parse()

bool tson::Tile::parse ( IJson json,
tson::Tileset tileset,
tson::Map map 
)
inline

Parses a tile from a Tiled json. id on tile is store as id + 1 to match the references in data containers.

Parameters
json
Returns

◆ parseId()

bool tson::Tile::parseId ( IJson json)
inline

◆ setProperties()

void tson::Tile::setProperties ( const tson::PropertyCollection properties)
inline

Friends And Related Symbol Documentation

◆ Layer

friend class Layer
friend

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