Window class forward declaration.
More...
#include <Drawable.h>
Window class forward declaration.
Interface for drawable objects
Definition at line 37 of file Drawable.h.
◆ Ptr
Shared object pointer.
Definition at line 45 of file Object.h.
◆ draw()
virtual void ime::Drawable::draw |
( |
Window & |
renderTarget | ) |
const |
|
pure virtual |
◆ emit()
void ime::Object::emit |
( |
const std::string & |
event | ) |
|
|
protectedinherited |
Dispatch an action event.
- Parameters
-
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)
- See also
- emitChange
◆ emitChange()
void ime::Object::emitChange |
( |
const Property & |
property | ) |
|
|
protectedinherited |
Dispatch a property change event.
- Parameters
-
property | The property that changed |
This function will invoke all the event listeners of the specified property
- See also
- emit
◆ getClassName()
virtual std::string ime::Object::getClassName |
( |
| ) |
const |
|
pure virtualinherited |
Get the name of the concrete class.
- Returns
- The name of the objects concrete class
This function is implemented by all internal classes that inherit from this class.
- See also
- getClassType
Implemented in ime::Tile, ime::SpriteSheet, ime::Sprite, ime::RectangleShape, ime::ConvexShape, ime::CircleShape, ime::Camera, ime::Scene, ime::RenderLayerContainer, ime::RenderLayer, ime::TargetGridMover, ime::RandomGridMover, ime::KeyboardGridMover, ime::DistanceJoint, ime::PolygonCollider, ime::EdgeCollider, ime::CircleCollider, ime::BoxCollider, ime::Body, ime::AABB, and ime::GameObject.
◆ getClassType()
std::string ime::Drawable::getClassType |
( |
| ) |
const |
|
inlineoverridevirtual |
◆ getObjectId()
unsigned int ime::Object::getObjectId |
( |
| ) |
const |
|
inherited |
Get the id of the object.
- Returns
- The id of the object
Each object has a unique id
◆ getTag()
const std::string& ime::Object::getTag |
( |
| ) |
const |
|
inherited |
Get the alias of the object.
- Returns
- The alias of the object
- See also
- setTag and getObjectId
◆ onDestruction()
int ime::Object::onDestruction |
( |
const Callback<> & |
callback | ) |
|
|
inherited |
Add a destruction listener.
- Parameters
-
callback | Function to be executed when the object is destroyed |
- Returns
- The id of the destruction listener
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
- Warning
- The callback is called when the object is destroyed. Do not try to access the object in the callback. Doing so is undefined behavior
- See also
- removeDestructionListener
◆ onEvent()
int ime::Object::onEvent |
( |
const std::string & |
event, |
|
|
const Callback<> & |
callback |
|
) |
| |
|
inherited |
Add an event listener to an event.
- Parameters
-
event | The name of the event to add an an event listener to |
callback | The function to be executed when the event takes place |
- Returns
- The unique identification number of the event listener
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:
object.onEvent("attachRigidBody", [] {
std::cout << "Rigid body attached to object << std::endl;
});
object.onEvent("removeRigidBody", [] {
std::cout << "Rigid body removed from object << std::endl;
});
object.attachRigidBody(body);
object.removeRigidBody();
- See also
- onPropertyChange and unsubscribe
◆ onPropertyChange() [1/2]
Add an event listener to a property change event.
- Parameters
-
callback | The function to be executed when the property changes |
- Returns
- The unique id of the event listener
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.
- See also
- onPropertyChange(std::string, Callback)
◆ onPropertyChange() [2/2]
int ime::Object::onPropertyChange |
( |
const std::string & |
property, |
|
|
const Callback< Property > & |
callback |
|
) |
| |
|
inherited |
Add an event listener to a specific property change event.
- Parameters
-
property | The name of the property to listen for |
callback | The function to be executed when the property changes |
- Returns
- The unique id of the event listener
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:
player.onPropertyChange("tag", [](const Property& property) {
cout << "New tag: " << property.getValue<std::string>() << endl;
});
...
player.setTag("player1");
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
- See also
- unsubscribe and onPropertyChange(Callback)
◆ operator!=()
bool ime::Object::operator!= |
( |
const Object & |
rhs | ) |
const |
|
inherited |
Check if two objects are not the same object.
- Parameters
-
rhs | Object to compare against this object |
- Returns
- True if rhs is NOT the same object as this object, otherwise false
Two objects are different from each other if they have different object id's
- See also
- getObjectId and operator==
◆ operator==()
bool ime::Object::operator== |
( |
const Object & |
rhs | ) |
const |
|
inherited |
Check if two objects are the same object or not.
- Parameters
-
rhs | Object to compare against this object |
- Returns
- True if rhs is the same object as this object, otherwise false
Two objects are the same object if they have the same object id. Recall that each object instance has a unique id
- See also
- getObjectId and operator!=
◆ removeDestructionListener()
bool ime::Object::removeDestructionListener |
( |
int |
id | ) |
|
|
inherited |
Remove a destruction listener form the object.
- Parameters
-
The | id of the destruction listener to be removed |
- Returns
- True if the destruction listener was removed or false if the listener with the given id does not exist
◆ setTag()
void ime::Object::setTag |
( |
const std::string & |
tag | ) |
|
|
inherited |
Assign the object an alias.
- Parameters
-
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
◆ unsubscribe()
bool ime::Object::unsubscribe |
( |
const std::string & |
event, |
|
|
int |
id |
|
) |
| |
|
inherited |
Remove an event listener from an event.
- Parameters
-
event | The name of the event to remove event listener from |
id | The unique id of the event listener to be removed |
- Returns
- True if the event listener was removed or false if the event or the event listener is does not exist
auto nameChangeId = object.onPropertyChange("name", [](Property name) {
std::cout << name.getValue<std::string>() << std::endl;
});
object.unsubscribe("name", id);
The documentation for this class was generated from the following file: