1
Graphics / Re: Moving rectangle
« on: November 02, 2021, 02:38:39 pm »
Thank you very much, i used move function to solve te problem. It toke me lot of time trying to solve it!!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
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;
}