A layer for drawable entities. More...
#include <RenderLayer.h>
Public Types | |
using | Ptr = std::shared_ptr< RenderLayer > |
Shared render layer pointer. More... | |
Public Member Functions | |
RenderLayer (const RenderLayer &)=delete | |
Copy constructor. More... | |
RenderLayer & | operator= (const RenderLayer &)=delete |
Copy assignment operator. More... | |
RenderLayer (RenderLayer &&) noexcept=default | |
Move constructor. More... | |
RenderLayer & | operator= (RenderLayer &&) noexcept=default |
Move assignment operator. More... | |
std::string | getClassName () const override |
Get the name of this class. More... | |
void | setDrawable (bool render) |
Set whether or not the layer should be drawn by the scene. More... | |
bool | isDrawable () const |
Check whether or not the layer is drawn by the scene. More... | |
void | toggleDrawable () |
Toggle the draw state of the layer. More... | |
unsigned int | getIndex () const |
Get the index of the layer in the RenderLayerContainer. More... | |
const std::string & | getName () const |
Get the name of the layer. More... | |
void | add (Drawable &drawable, int renderOrder=0) |
Add a drawable to the layer. More... | |
bool | has (const Drawable &drawable) const |
Check if the render layer has a given drawable or not. More... | |
bool | remove (Drawable &drawable) |
Remove a drawable from the render layer. More... | |
void | removeAll () |
Remove all drawables from the render layer. More... | |
std::size_t | getCount () const |
Get the number of drawables rendered by the layer. More... | |
void | render (priv::RenderTarget &window) const |
~RenderLayer () override | |
Destructor. 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... | |
virtual std::string | getClassType () const |
Get the name of the direct parent of an object instance. 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... | |
Friends | |
class | RenderLayerContainer |
Needs access to constructor. More... | |
A layer for drawable entities.
Typically you add objects that should be drawn together to the same layer. The order in which render layers are rendered is specified in the RenderLayerContainer. Objects in the same layer can also be sorted. For example, you may have a background layer which has mountains, trees and valleys. However you don't want the objects to be drawn non-deterministically. You can specify which objects are drawn over which and which objects are drawn under which by specifying the render order of the object when adding it to the layer. Objects with the lowest render order are drawn first whilst objects with the highest render order are drawn last. When objects have the same render order, the object that was added first to the layer will be rendered first.
By default, all objects have the same render order, as a result, they are drawn in the order in which they were added to the layer
A layer is not instantiated directly but rather using a ime::RenderLayerContainer::create
Definition at line 64 of file RenderLayer.h.
using ime::RenderLayer::Ptr = std::shared_ptr<RenderLayer> |
Shared render layer pointer.
Definition at line 66 of file RenderLayer.h.
|
delete |
Copy constructor.
|
defaultnoexcept |
Move constructor.
|
override |
Destructor.
void ime::RenderLayer::add | ( | Drawable & | drawable, |
int | renderOrder = 0 |
||
) |
Add a drawable to the layer.
drawable | The drawable to be added |
renderOrder | The layer level render order of the drawable |
The render order determines which game objects get rendered first and which game objects get rendered last in the layer. Therefore the order in which drawables are added to the layer does not necessarily matter. Drawables with the smallest render order are be rendered first. Note that multiple drawables can have the same render order, in such a case the drawables will be drawn in the order in which they were added to the layer
By default, all drawables have the same render order of 0
|
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 |
|
virtualinherited |
Get the name of the direct parent of an object instance.
In contrast to getClassName() which returns the name of the concrete class, this function returns the name of the concrete class's base class. This function is implemented by all derived classes of ime::Object which also serve as base classes. For classes whose direct parent is this class, this function will return the name of this class
Reimplemented in ime::audio::Audio, ime::GameObject, ime::GridMover, ime::Collider, ime::Joint, ime::Drawable, ime::Shape, and ime::SpriteImage.
std::size_t ime::RenderLayer::getCount | ( | ) | const |
Get the number of drawables rendered by the layer.
unsigned int ime::RenderLayer::getIndex | ( | ) | const |
Get the index of the layer in the RenderLayerContainer.
The index indicates the render order of the layer. The bigger the index the further away the layer is from the foreground. The layer with the an index of 0 is always the foreground layer and all other layers are rendered behind it
const std::string & ime::RenderLayer::getName | ( | ) | const |
Get the name of the layer.
|
inherited |
Get the unique id of the object.
Note that each instance of ime::Object has a unique id
|
inherited |
bool ime::RenderLayer::has | ( | const Drawable & | drawable | ) | const |
Check if the render layer has a given drawable or not.
drawable | The drawable to be checked |
When a render layer "has" a drawable, it means that the drawable is rendered by that layer to the render window
bool ime::RenderLayer::isDrawable | ( | ) | const |
Check whether or not the layer is drawn by the scene.
|
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 |
|
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.
|
delete |
Copy assignment operator.
|
defaultnoexcept |
Move assignment operator.
bool ime::RenderLayer::remove | ( | Drawable & | drawable | ) |
Remove a drawable from the render layer.
drawable | The drawable to be removed |
When a drawable is removed from the render layer, it will no longer be rendered by the scene, hence it won't appear on the game window
void ime::RenderLayer::removeAll | ( | ) |
Remove all drawables from the render layer.
|
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::RenderLayer::setDrawable | ( | bool | render | ) |
Set whether or not the layer should be drawn by the scene.
render | True to have the layer drawn by the scene otherwise false |
By default the layer is drawable
|
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
|
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::RenderLayer::toggleDrawable | ( | ) |
Toggle the draw state of the layer.
This function will set the layer to drawable if its currently not drawable and vice versa
|
friend |
Needs access to constructor.
Definition at line 228 of file RenderLayer.h.
|
protectedinherited |