I am taking the step of moving on from Java over to c++, I have been working on my own custom game engine in java for a while so have a good understanding of polymophism, inheritance etc.
Now to the issue:
Currently I am working on a basic level format trying to get entities to render to the screen, this all goes well if i change the code to what i don't want it to be below is the code:
#include <SFML/Graphics.hpp>
#include "../Entities/Player.h"
#include "Layer.h"
class TileMap: public sf::Drawable, public sf::Transformable {
private:
std::vector<Player> entities;
public:
Player* addEntity(Player player) {
entities.push_back(player);
return &entities[entities.size() - 1];
}
void update() {
for (unsigned int i = 0; i < entities.size(); i++) {
entities[i].update();
}
}
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const {
for (unsigned int i = 0; i < entities.size(); i++) {
target.draw(entities[i]);
}
}
};
The player that is returned in the function is then stored in a DrawableEntiity* player; variable. & this works fine everything updates
As I want a generalized list of entities and not a list for each entity i add to the game i want to be able to change this from
std::vector<Player> entities;
and change it too (obviously including the include for it too)
std::vector<DrawableEntity> entities;
The issue is everytime i store it this way the draw and update functions of the lower level Entity class isn't called and instead the default function inside of the DrawableEntity is called.
This is probably a easy mistake on something I've overlooked but i can't find anything online anywhere that fixes the issue. a full code listing of the Entity classes can be found at http://pastebin.com/3rRuzZHs
Thanks for taking your time to read this Jordan
P.S: If you need any more information let me know.