user3678306
user3678306

Reputation: 27

SFML not drawing shape when I call the shape's constructor " shape() "

My player " rectangle " won't draw unless I do this in the member initialization:

mPLayer(sf::Vector2f(10,10))

even though I've already done this in the constructor definition:

mPLayer.setPosition(50,50);
    mPLayer.setFillColor(sf::Color::Green);

The problem is I want to use a std::vector to store many shapes and control them but it won't work " not drawing " when I do this:

In the header:

std::vector<sf::RectangleShape>mPlayerScale;

in the implementation:

mPlayerScale.resize(3);
    mPlayerScale[0].setPosition(0.f,0.f);
    mPlayerScale[1].setPosition(101,101);
    mPlayerScale[2].setPosition(101,101);
    mPlayerScale[0].setFillColor(sf::Color::Red);
    mPlayerScale[1].setFillColor(sf::Color::Green);
    mPlayerScale[2].setFillColor(sf::Color::Blue);

and since mPlayer() is not working when I call it then the vector won't work " won't draw "

Upvotes: 0

Views: 1225

Answers (1)

Cornstalks
Cornstalks

Reputation: 38218

The default size for a rectangle is 0 x 0. That's why it won't draw.

Either pass in a sf::Vector2f to the constructor to specify the size, or use the setSize() method.

Upvotes: 3

Related Questions