SFML community forums

Help => Window => Topic started by: Aerine on April 20, 2017, 12:29:53 am

Title: window.draw(spritename) drawing sprites over and over in a loop. Bad??
Post by: Aerine on April 20, 2017, 12:29:53 am
I havent loaded textures in until i get my resource management class going. Drawing the sprites over and over in a loop dosent seem to stress the computer that much. But if there is no need to draw why draw. For example I have a render function that draws all my monsters and sprites through arrays while the window is open.
for (int i = 0; i < myfirearray.size(); i++)
        {
                window.draw(myfirearray[i]);
        }

Now this will tick through the game loop and keep drawing and drawing and drawing these sprites over and over. How bad is this. Should i not draw these in a loop? I currently don't have textures yet, because I know there not lightweight and i want to make a management class. Im not looking to create the most amazing best game in the world something simple and educational. But i dont wanna run into a problem later.
Title: Re: window.draw(spritename) drawing sprites over and over in a loop. Bad??
Post by: Hapax on April 20, 2017, 04:38:23 pm
It's acceptable to draw many items if you have many items to draw.

If you begin to find that you're drawing hundreds or thousands of sprites and that is causing your game to slow down, you may want to consider looking into batching them into an sf::VertexArray:
https://www.sfml-dev.org/tutorials/2.4/graphics-vertex-array.php