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

Author Topic: [SOLVED] Reusing a single sf::Sprite through a game: good or bad idea?  (Read 1682 times)

0 Members and 1 Guest are viewing this topic.

elvaka

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
I'm using a single sf::Sprite and sf::Texture for my entire game. My Texture contains my game's entire tileset and, every time I need to draw something, I update the TextureRect in the Sprite like this:

Code: [Select]
sprite.setTextureRect(<whatever>);

I found that, since I have to update the position and maybe scale, etc. on the sprite every frame anyway, I might as well update its TextureRect instead of storing lots of different sf::Sprite objects.

Is there any downside to doing this? Am I missing on some optimization (batching draws, etc.) because of this?

Thanks a lot, folks!
« Last Edit: April 02, 2020, 08:53:31 pm by elvaka »

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Reusing a single sf::Sprite through a game: good or bad idea?
« Reply #1 on: April 02, 2020, 12:47:00 pm »
no, in contrary, what did you do is the most optimal way to handle the texturing efficiently with SFML or 2D graphics in general. this method sometime is called atlas-texture or texture-atlas i'm not sure.  ;D

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Reusing a single sf::Sprite through a game: good or bad idea?
« Reply #2 on: April 02, 2020, 02:17:21 pm »
Many sprites or a single one that you keep modifying, should not make any difference at all. Just look at its (very simple) implementation and you'll understand.

Choose the solution that's more intuitive/readable/whatever for your own code.
Laurent Gomila - SFML developer

elvaka

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Thanks a lot for your responses! You are the best ❤️

 

anything