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

Author Topic: window.draw(spritename) drawing sprites over and over in a loop. Bad??  (Read 819 times)

0 Members and 1 Guest are viewing this topic.

Aerine

  • Newbie
  • *
  • Posts: 10
    • View Profile
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.

Hapax

  • Hero Member
  • *****
  • Posts: 3043
  • My number of posts is shown in hexadecimal.
    • View Profile
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
Selba Ward - SFML drawables
Kairos - Timing Library
Rectangular Boundary Collision - Rectangular SAT Collision

@Hapaxiation - Hapaxia on Twitter

 

anything