I created an entity-basic class and the entities are managed by an entity-manager. I also created an asteroid class, which inherits from the entity class. The manager adds the entities to a list and calls their functions:
class EntityManager
{
public:
EntityManager(sf::RenderWindow *rw,sf::Event *ev);
~EntityManager();
void Render();
void Update(float frametime);
void HandleEvents();
void AddEntity(Entity* entity);
void KillEntity(std::string id);
Entity GetEntity(std::string id);
private:
std::list<Entity> mEntityList;
std::list<Entity>::iterator mEntityIt;
sf::RenderWindow *mRenderWindow;
sf::Event *mEvent;
};
E.g. the render function:
void EntityManager::Render()
{
for(mEntityIt = mEntityList.begin(); mEntityIt != mEntityList.end(); mEntityIt++)
{
mEntityIt->Render(mRenderWindow);
}
}
I declared the functions of the basic class as virtual functions and overwrote them at the asteroid class. The problem is that the manager only accesses the functions of the basic entity class, but not the functions of the asteroid class.
class Entity
{
public:
Entity(std::string id);
~Entity();
virtual void Render (sf::RenderWindow *rw);
virtual void Update (float frametime);
virtual void HandleEvents (sf::Event *ev);
sf::Sprite* GetSprite() {return mSprite;};
sf::Texture* GetTexture() {return mTexture;};
std::string GetID() {return mID;};
bool GetAlive() {return mIsAlive;};
void SetID(std::string id) {mID = id;};
private:
sf::Texture *mTexture;
sf::Sprite *mSprite;
std::string mID;
bool mIsAlive;
};
class Asteroid : public Entity
{
public:
Asteroid(std::string id);
void Render (sf::RenderWindow *rw);
void Update (float frametime);
void HandleEvents (sf::Event *ev);
void UpdateMovement(float frametime);
private:
float mSize;
int mYPosition;
int mRotation;
int mSpeed;
};
Can I access the functions of the asteroid class by the entity-manager?
I hope I've explained my problem understandable, please ask if you need further information.