Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problem with Shape and adress stuff  (Read 1162 times)

0 Members and 1 Guest are viewing this topic.

ulko10

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Problem with Shape and adress stuff
« on: May 15, 2015, 05:49:25 pm »
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.

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: Problem with Shape and adress stuff
« Reply #1 on: May 15, 2015, 05:59:56 pm »
Because no one else has said it yet, I'd like to be the one to suggest using RAII instead of naked news. It will also make it easier to work out where the problem is if you don't reference a virtual function from within it's redefinition. I'm not absolutely sure it's a bad idea, but it seems very wrong, rather than just writing the method out again so the function works on its own. Also, could you post a screenshot of what is happening?

ulko10

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: Problem with Shape and adress stuff
« Reply #2 on: May 15, 2015, 06:05:45 pm »
Here is a screen: http://grab.by/Hjsu

Thank you.


 

anything