#include <Tile.h>
Public Types | |
using | Ptr = std::unique_ptr< Object > |
Unique 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=default | |
Move constructor. More... | |
Tile & | operator= (Tile &&) noexcept=default |
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 grid. More... | |
Index | getIndex () const |
Get the index of the tile in the grid. 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::unique_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 | swap (Tile &other) |
Swap the contents of this tile with that of another tile. More... | |
void | setBody (RigidBody::Ptr body) |
Set the tiles RigidBody. More... | |
void | draw (priv::RenderTarget &renderTarget) const override |
Draw object on a render target. 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 tag assigned to the object. More... | |
unsigned int | getObjectId () const |
Get the unique id of the object. More... | |
int | onPropertyChange (const std::string &property, const Callback< Property > &callback, bool oneTime=false) |
Add an event listener to a specific property change event. More... | |
int | onPropertyChange (const Callback< Property > &callback, bool oneTime=false) |
Add an event listener to any property change event. More... | |
void | suspendedEventListener (int id, bool suspend) |
Pause or resume execution of an event listener. More... | |
bool | isEventListenerSuspended (int id) const |
Check if an event listener is suspended or not. More... | |
bool | removeEventListener (const std::string &event, int id) |
Remove an event listener from an event. More... | |
bool | removeEventListener (int id) |
Remove an event listener. More... | |
int | onDestruction (const Callback<> &callback) |
Add a destruction listener. More... | |
bool | isSameObjectAs (const Object &other) const |
Check if another object is the same instance as this object. More... | |
Protected Member Functions | |
void | emitChange (const Property &property) |
Dispatch a property change event. More... | |
void | emitDestruction () |
Emit a destruction event. More... | |
Protected Attributes | |
EventEmitter | eventEmitter_ |
Event dispatcher. More... | |
|
inherited |
Construct a tile.
size | Size of the tile |
position | Position of the tile |
ime::Tile::Tile | ( | const Tile & | ) |
Copy constructor.
|
defaultnoexcept |
Move constructor.
|
override |
Destructor.
void ime::Tile::attachCollider | ( | std::unique_ptr< BoxCollider > | collider | ) |
Add a collider to the tile.
collider | The collider to be added |
Without a Collider, only game objects that are controlled by a GridMover can collide with the tile. Attaching a collider makes a GameObject with a RigidBody that has a Collider attached to it able to collide with the tile. The tile can can only have one collider attached to it. The current collider must be removed first before attaching a new one
By default, the tile does not have a collider attached to it
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 a property change event.
property | The property that changed |
This function will invoke all the event listeners of the specified property
|
protectedinherited |
Emit a destruction event.
|
overridevirtual |
|
overridevirtualinherited |
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.
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 grid.
Note that each tile in the grid has a unique index
Vector2f ime::Tile::getLocalCentre | ( | ) | const |
Get the tile's centre point in local coordinates.
|
inherited |
Get the unique id of the object.
Note that each instance of ime::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.
|
inherited |
Check if an event listener is suspended or not.
id | The identification number of the listener to be checked |
This function also returns false if the specified event listener does not exist
|
inherited |
Check if another object is the same instance as this object.
other | The object to compare against this object |
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 |
The destruction listener is called when the object reaches the end of its lifetime. Note that an object may have multiple destruction listeners registered to it
|
inherited |
Add an event listener to any property change event.
callback | The function to be executed when any property changes |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
When unsubscribing the any property change event handler, you must pass "propertyChange" as the name of the event
|
inherited |
Add an event listener to a specific property change event.
property | The name of the property to add an event listener to |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
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, the setTag() function, modifies the tag property of the object, thus will generate a "tag" change event each time it is called
Note that multiple event listeners may be registered to the same property change event. In addition, when adding a property change event listener, the name of the property must be in lowercase.
void ime::Tile::removeCollider | ( | ) |
Remove the collider added to the tile.
Note that when the collider is removed, the tile will no longer participate in RigidBody physics, however grid-based physics (see ime::GridMover) will continue as normal.
|
inherited |
Remove an event listener from an event.
event | The name of the event to remove an event listener from |
id | The unique id of the event listener to be removed |
|
inherited |
Remove an event listener.
id | The id of the event listener to be removed |
void ime::Tile::setBody | ( | RigidBody::Ptr | body | ) |
Set the tiles RigidBody.
body | The physics body to set |
The rigid body is only required if you intend to attach a Collider. The rigid body must be of type ime::RigidBody::Type::Static
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 had a Collider attached to it does not remove the collider. This removes the need to create a new collider everytime the collidability of the tile is re-enabled. The collider can be explicitly removed from the tile by calling the removeCollider() function
By default, the tile is 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 grid.
index | The index of the tile in the grid |
The index corresponds to the position of the tile in the grid
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.
tag | The alias of the object |
This function is useful if you want to refer to the object by a tag instead of its object 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
|
inherited |
Pause or resume execution of an event listener.
id | The event listeners unique identification number |
suspend | True to suspend/pause or false to unsuspend/resume |
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
|
protectedinherited |