A Tilemap tile. More...
#include <Tile.h>
Public Types | |
using | Ptr = std::shared_ptr< Object > |
Shared object pointer. More... | |
Public Member Functions | |
Tile (Vector2u size, Vector2f position) | |
Construct a tile. More... | |
Tile (const Tile &) | |
Copy constructor. More... | |
Tile & | operator= (Tile) |
Copy assignment operator. More... | |
Tile (Tile &&) noexcept | |
Move constructor. More... | |
Tile & | operator= (Tile &&) noexcept |
Move assignment operator. More... | |
void | setPosition (float x, float y) |
Set the position of the tile. More... | |
void | setPosition (Vector2f pos) |
Set the position of the tile. More... | |
Vector2f | getPosition () const |
Get the position of the tile. More... | |
void | setSize (unsigned int width, unsigned int height) |
Set the size of the tile. More... | |
void | setSize (Vector2u size) |
Set the size of the tile. More... | |
Vector2u | getSize () const |
Get the size of the tile. More... | |
void | setVisible (bool visible) |
Show or hide the tile. More... | |
bool | isVisible () const |
Check whether or not the tile is visible. More... | |
void | setIndex (Index index) |
Set the index of the tile in the tilemap. More... | |
Index | getIndex () const |
Get the index of the tile in the tilemap. More... | |
void | setId (char id) |
Assign the tile an identification token. More... | |
char | getId () const |
Get the id of the tile. More... | |
void | setCollidable (bool collidable) |
Set whether tile is collidable or not. More... | |
bool | isCollidable () const |
Check if the tile is collidable or not. More... | |
void | setFillColour (const Colour &colour) |
Set the fill colour of the tile. More... | |
Colour | getFillColour () const |
Get the fill colour of the tile. More... | |
std::string | getClassName () const override |
Get the name of this class. More... | |
Vector2f | getLocalCentre () const |
Get the tile's centre point in local coordinates. More... | |
Vector2f | getWorldCentre () const |
Get the tile's centre point in world coordinates. More... | |
bool | contains (Vector2f point) const |
Check if the tile contains a world coordinate. More... | |
void | attachCollider (std::shared_ptr< BoxCollider > collider) |
Add a collider to the tile. More... | |
void | removeCollider () |
Remove the collider added to the tile. More... | |
bool | hasCollider () const |
Check if the tile has a collider or not. More... | |
void | toggleVisibility () |
Toggle the visibility of the tile. More... | |
void | draw (Window &renderTarget) const override |
Draw object on a render target. More... | |
void | swap (Tile &other) |
Swap the contents of this tile with that of another tile. More... | |
~Tile () override | |
Destructor. More... | |
std::string | getClassType () const override |
Get the name of this class. More... | |
void | setTag (const std::string &tag) |
Assign the object an alias. More... | |
const std::string & | getTag () const |
Get the alias of the object. More... | |
unsigned int | getObjectId () const |
Get the id of the object. More... | |
int | onPropertyChange (const std::string &property, const Callback< Property > &callback) |
Add an event listener to a specific property change event. More... | |
void | onPropertyChange (const Callback< Property > &callback) |
Add an event listener to a property change event. More... | |
int | onEvent (const std::string &event, const Callback<> &callback) |
Add an event listener to an event. More... | |
bool | unsubscribe (const std::string &event, int id) |
Remove an event listener from an event. More... | |
int | onDestruction (const Callback<> &callback) |
Add a destruction listener. More... | |
bool | removeDestructionListener (int id) |
Remove a destruction listener form the object. More... | |
bool | operator== (const Object &rhs) const |
Check if two objects are the same object or not. More... | |
bool | operator!= (const Object &rhs) const |
Check if two objects are not the same object. More... | |
Protected Member Functions | |
void | emitChange (const Property &property) |
Dispatch a property change event. More... | |
void | emit (const std::string &event) |
Dispatch an action event. More... | |
|
inherited |
Construct a tile.
size | Size of the tile |
position | Position of the tile |
ime::Tile::Tile | ( | const Tile & | ) |
Copy constructor.
|
noexcept |
Move constructor.
|
override |
Destructor.
void ime::Tile::attachCollider | ( | std::shared_ptr< BoxCollider > | collider | ) |
Add a collider to the tile.
collider | The collider to be added |
Note that a tile can only have one collider attached to it. The current collider must be removed first before attaching a new one
bool ime::Tile::contains | ( | Vector2f | point | ) | const |
Check if the tile contains a world coordinate.
point | The point (in world coordinates) to be checked |
|
overridevirtual |
Draw object on a render target.
renderTarget | Target to draw object on |
Implements ime::Drawable.
|
protectedinherited |
Dispatch an action event.
event | The name of the event to be dispatched |
This function will invoke all event listeners of the specified event. The function should be used for events that represent an action, rather than those that represent a property change (Use emitChange for that)
|
protectedinherited |
Dispatch a property change event.
property | The property that changed |
This function will invoke all the event listeners of the specified property
|
overridevirtual |
|
inlineoverridevirtualinherited |
Get the name of this class.
Note that this function is only overridden by child classes of Object which also serve as a base class for other classes
Reimplemented from ime::Object.
Reimplemented in ime::Shape.
Definition at line 48 of file Drawable.h.
Colour ime::Tile::getFillColour | ( | ) | const |
Get the fill colour of the tile.
char ime::Tile::getId | ( | ) | const |
Get the id of the tile.
Index ime::Tile::getIndex | ( | ) | const |
Get the index of the tile in the tilemap.
Note that each tile in the tilemap has a unique index
Vector2f ime::Tile::getLocalCentre | ( | ) | const |
Get the tile's centre point in local coordinates.
|
inherited |
Get the id of the object.
Each object has a unique id
Vector2f ime::Tile::getPosition | ( | ) | const |
Get the position of the tile.
Vector2u ime::Tile::getSize | ( | ) | const |
Get the size of the tile.
|
inherited |
Vector2f ime::Tile::getWorldCentre | ( | ) | const |
Get the tile's centre point in world coordinates.
bool ime::Tile::hasCollider | ( | ) | const |
Check if the tile has a collider or not.
bool ime::Tile::isCollidable | ( | ) | const |
Check if the tile is collidable or not.
bool ime::Tile::isVisible | ( | ) | const |
Check whether or not the tile is visible.
|
inherited |
Add a destruction listener.
callback | Function to be executed when the object is destroyed |
Note that an object may have more than one destruction listeners, however, you have to keep the returned id if you may want to remove the callback at a later time
|
inherited |
Add an event listener to an event.
event | The name of the event to add an an event listener to |
callback | The function to be executed when the event takes place |
Unlike onPropertyChange, this function registers event listeners to events that occur when something happens to the object, or when the object does something (action events). Usually the name of the event/action is the name of the function:
Add an event listener to a property change event.
callback | The function to be executed when the property changes |
Note that only one callback function may be registered with this function. This means that adding a new event listener overwrites the previous event listener. To remove the callback, pass a nullptr as an argument. The function may be useful if you want to write the logic for property changes in one function.
|
inherited |
Add an event listener to a specific property change event.
property | The name of the property to listen for |
callback | The function to be executed when the property changes |
A property change event is triggered by any function that begins with set, where the the text after set is the name of the property. For example, for the setTag function, the property that the function modifies is Tag.
Note that when adding a property change event listener, the name of the property must be in lowercase:
Unlike onPropertyChange(const Callback&) you can add multiple event listeners to the same property using this function. However you must store the unique id of the event listener if you wish to remove it at a later time
|
inherited |
Check if two objects are not the same object.
rhs | Object to compare against this object |
Two objects are different from each other if they have different object id's
|
inherited |
Check if two objects are the same object or not.
rhs | Object to compare against this object |
Two objects are the same object if they have the same object id. Recall that each object instance has a unique id
void ime::Tile::removeCollider | ( | ) |
Remove the collider added to the tile.
Note that if the tile is collidable and the collider is removed, it will no longer be collidable. This function has no effect if the tile does not have a collider attached to it
|
inherited |
Remove a destruction listener form the object.
The | id of the destruction listener to be removed |
void ime::Tile::setCollidable | ( | bool | collidable | ) |
Set whether tile is collidable or not.
collidable | True to set collidable, otherwise false |
Note that disabling a collision for a tile that was previously collidable does not remove the tiles collider. This removes the need to create a new collider everytime the collidability of the tile is re-enabled. The collider can be removed from the tile by calling the removeCollider function
By default, the tile does not have a collider attached to it, hence not collidable
void ime::Tile::setFillColour | ( | const Colour & | colour | ) |
Set the fill colour of the tile.
colour | New fill colour of the tile |
void ime::Tile::setId | ( | char | id | ) |
Assign the tile an identification token.
id | Identification token to assign |
By default, the tile id is '\0'
Note that multiple tiles can have the same identification token
void ime::Tile::setIndex | ( | Index | index | ) |
Set the index of the tile in the tilemap.
index | The index of the tile in the tilemap |
The index corresponds to the position of the tile in the tilemap
By default, the index is (-1, -1)
void ime::Tile::setPosition | ( | float | x, |
float | y | ||
) |
Set the position of the tile.
x | X coordinate of the tile |
y | Y coordinate of the tile |
By default, the position is (0, 0)
void ime::Tile::setPosition | ( | Vector2f | pos | ) |
Set the position of the tile.
pos | The new position of the tile |
By default, the position is (0, 0)
void ime::Tile::setSize | ( | unsigned int | width, |
unsigned int | height | ||
) |
Set the size of the tile.
width | The horizontal size |
height | The vertical size |
void ime::Tile::setSize | ( | Vector2u | size | ) |
Set the size of the tile.
size | New tile size |
|
inherited |
Assign the object an alias.
name | The alias of the object |
This function is useful if you want to refer to the object by tag instead of its id. Unlike an object id, multiple objects may have the same tag.
By default, the tag is an empty string
void ime::Tile::setVisible | ( | bool | visible | ) |
Show or hide the tile.
visible | True to show or false to hide |
When hidden the tile will not be shown on the render target, However it can still be collided with if its collidable
By default, the tile is visible
void ime::Tile::swap | ( | Tile & | other | ) |
Swap the contents of this tile with that of another tile.
other | The tile to swap contents with |
void ime::Tile::toggleVisibility | ( | ) |
Toggle the visibility of the tile.
This function will hide the tile if its currently visible or show it if it is currently hidden
|
inherited |
Remove an event listener from an event.
event | The name of the event to remove event listener from |
id | The unique id of the event listener to be removed |