Hello to everyone. I'm trying to create step by ste a snake, but i'm struggling with simple body creation. can you explain me why my code does not renders thee rectangle shapes as I want.
int main(int argc, char **argv)
{
sf::RenderWindow window(sf::VideoMode(600, 600), "Snake");
std::vector<sf::RectangleShape> body(3);
for (int i = 0; i < 3; i++)
{
body.push_back(sf::RectangleShape(sf::Vector2f(100, 100)));
body[i].setFillColor(sf::Color::Green);
}
body[0].setPosition(100, 200);
body[1].setPosition(205, 200);
body[2].setPosition(310, 200);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(body[0]);
window.draw(body[1]);
window.draw(body[2]);
window.display();
}
return 0;
}