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

Author Topic: Draw sprite to renderwindow automatically  (Read 550 times)

0 Members and 1 Guest are viewing this topic.

Me-Myself-And-I

  • Newbie
  • *
  • Posts: 48
    • View Profile
Draw sprite to renderwindow automatically
« on: December 23, 2022, 12:44:58 am »
Hi everyone.
I was wondering if theres a more automated way to draw sprites to the window.
Everthing sfml related i've seen has drawn sprites to the window by typing out every sprite that the window should draw.
window.clear();
window.draw(sprite1);
window.draw(sprite2);
window.draw(sprite3);
window.draw(sprite4);
window.draw(sprite5);
window.draw(sprite6);
window.draw(sprite7);
and so on...

Is there a more efficient way thats more automated?Maybe by a class?   

fallahn

  • Sr. Member
  • ****
  • Posts: 492
  • Buns.
    • View Profile
    • Trederia
Re: Draw sprite to renderwindow automatically
« Reply #1 on: December 23, 2022, 05:39:34 pm »
A simple approach would be to place your sprites in a vector, and loop over it when you draw:

std::vector<sf::Sprite> sprites;

//insert sprites here

for (const auto& sprite : sprites)
{
    window.draw(sprite);
}

However if you're getting more serious about your code design I highly recommend reading SFML Game Development and Game Programming Patterns - both of which I found invaluable when I was learning SFML.