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

Author Topic: Is it worth it to create as few sprites as possible  (Read 1948 times)

0 Members and 1 Guest are viewing this topic.

MaxV37

  • Newbie
  • *
  • Posts: 3
    • View Profile
Is it worth it to create as few sprites as possible
« on: July 05, 2016, 01:25:17 pm »
I am currently making a game with SFML and I wonder if I should reuse the same sf::Sprite to draw all of the entities that are on screen.
For example, if I wanted to draw 20 entities with the same texture, should I make them share the same sprite and move it to the position of the entity before drawing it or is it ok to use 20 sprites sharing the same sf::Texture ?

Same question for the terrain because there are much more sprites involved.

I am worried about slowing the game a lot, but I read that the important thing was to reuse the same texture instance so I am not sure that it is necessary to reuse the same sprite for every entity.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Is it worth it to create as few sprites as possible
« Reply #1 on: July 05, 2016, 01:31:44 pm »
Today's computers are pretty powerful. They can draw a few thousand quads with no problem at all. As such it doesn't really matter what path you choose and it's recommended to just pick one way and go with it. Once you run into actual performance issues, you can always refactor.

One option that might be interesting though, is the use of vertex arrays. That way you can draw as many primitive types as you want (using one texture) with a single draw call. Don't think too much about performance and instead try to implement the game and try to use a design that makes maintainability easy.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MaxV37

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Is it worth it to create as few sprites as possible
« Reply #2 on: July 05, 2016, 02:31:22 pm »
thank you very much for your help

 

anything