Gamedev Framework (gf)  0.8.0
A C++14 framework for 2D games
Public Member Functions | List of all members
gf::EntityContainer Class Reference

A collection of entities. More...

#include <gf/EntityContainer.h>

Public Member Functions

void update (Time time)
 Update the entities. More...
void render (RenderTarget &target, const RenderStates &states=RenderStates())
 Render the entities on the target. More...
Entities management
void addEntity (Entity &entity)
 Add an entity to the collection. More...
EntityremoveEntity (Entity *entity)
 Remove an entity from the collection. More...
template<typename E >
EremoveTypedEntity (E *entity)
 Remove a typed entity from the collection. More...

Detailed Description

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.

See also

Member Function Documentation

◆ addEntity()

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.

entityAn entity
See also

◆ removeEntity()

Entity* gf::EntityContainer::removeEntity ( Entity entity)

Remove an entity from the collection.

entityThe entity to remove
The removed entity or nullptr if the entity was not present
See also

◆ removeTypedEntity()

template<typename E >
E* gf::EntityContainer::removeTypedEntity ( E entity)

Remove a typed entity from the collection.

This function is a shortcut to avoid typecasting.


class Foo : public Entity {
Foo foo;
Foo *removed = manager.removeTypedEntity<Foo>(&foo);
See also

◆ render()

void gf::EntityContainer::render ( RenderTarget target,
const RenderStates states = RenderStates() 

Render the entities on the target.

The entities are rendered by priority: lower priority first and higher priority last.

targetThe render target
statesThe render states to use for drawing
See also

◆ update()

void gf::EntityContainer::update ( Time  time)

Update the entities.

This function first eliminates the dead entities, then sort them by priority. Finally, each entity is updated.

timeThe time since the last update
See also