Hi everybody,
I'm creating a little c++ game with sfml, here is a resume of what I want to do :
In my game there is Meteor and two type of these, Circle meteor and Rectangle Meteor. So I wanted to use polymorphism to stock these both type of meteor which are inherited from the same Meteor Class. So usually i have a virtual render function in Meteor that's like this :
virtual void render(sf::Shape &shape);
And after this the treatment is obviously different in Circle Meteor and Rectangle one. Here is the code of CircleMeteor, I don't put Rectangles one because anyway it will work the same way :
void BubbleMeteor::render(sf::Shape &shape) {
shape = CircleShape(m_size.x / 2);
Meteor::render(shape);
}
void Meteor::render(sf::Shape &shape) {
shape.setFillColor(m_color);
shape.setOutlineColor(Color::Black);
shape.setOutlineThickness(8);
shape.setOrigin(0, 0);
shape.setPosition(m_pos);
shape.setRotation(m_rotation);
}
And in the RenderManager i use it like that :
for (int i = 0; i < (int)m_metMng->getArray().size(); i++) {
Shape *shape = new RectangleShape(Vector2f(120,50));
m_metMng->getArray()[i]->render(*shape);
m_app->draw(*shape);
}
The "= new RectangleShape(Vector2f(120,50));" stuff was for iniatilazing I could have use "nullptr" but it was crashing since my assignation don't work in "BubbleMeteor::render(...);" I tested a lot of things and this is the one giving me the best result. I see every meteor with their respective color, rotation, position (So i can conclude "Meteor::render(...)" work great) but they don't adapt to size and circle or rectangle.
Can you say me how to fix this ?
Thanks you very much for you time.