Gamedev Framework (gf)
0.3.0
A C++11 framework for 2D games
|
A collection of entities. More...
#include <gf/EntityContainer.h>
Public Member Functions | |
void | update (float dt) |
Update the entities. More... | |
void | render (RenderTarget &target) |
Render the entities on the target. More... | |
Entities management | |
void | addEntity (Entity &entity) |
Add an entity to the collection. More... | |
Entity * | removeEntity (Entity *entity) |
Remove an entity from the collection. More... | |
template<typename E > | |
E * | removeTypedEntity (E *entity) |
Remove a typed entity from the collection. More... | |
A collection of entities.
gf::EntityContainer represents a collection of entities that are updated and rendered automatically. The entity manager takes care of the liveness of the entities and remove the dead entities from the collection.
The entity manager is not responsible for the memory of the entities. The entities must be allocated by the user and not deleted while they are handled by the entity manager.
Generally, you only need one entity manager in your game. You create it at the beginning of the game and put all your entities in it. Then you can call gf::EntityContainer::update() and gf::EntityContainer::render() in your game loop.
void gf::EntityContainer::addEntity | ( | Entity & | entity | ) |
Add an entity to the collection.
The entity must not be deleted while it is handled by the entity manager.
entity | An entity |
Remove an entity from the collection.
entity | The entity to remove |
nullptr
if the entity was not present Remove a typed entity from the collection.
This function is a shortcut to avoid typecasting.
Example:
void gf::EntityContainer::render | ( | RenderTarget & | target | ) |
Render the entities on the target.
The entities are rendered by priority: lower priority first and higher priority last.
target | The render target |
void gf::EntityContainer::update | ( | float | dt | ) |
Update the entities.
This function first eliminates the dead entities, then sort them by priority. Finally, each entity is updated.
dt | The time (in seconds) since the last update |