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

Author Topic: About sprites.  (Read 1171 times)

0 Members and 1 Guest are viewing this topic.

jammer312

  • Newbie
  • *
  • Posts: 3
    • View Profile
About sprites.
« on: March 16, 2014, 10:38:57 am »
I made class that have sf::Sprite or vector of sf::Sprite. Is there any way to make them work without existing texture?
I mean that I load sprites object(made by me, to handle sf::sprites) by loading image file into texture that created using 'new'. Then I load texture into sprite and finally make object with copy of that sprite. But it cost big amount of perfomance as I read in tutorial to change textures. So, is there any way to either construct one texture made of other textures, so I can load .png file into texture, then append my texture and somehow draw my newly created texture on that texture and delete newly created texture, so it's like appending texture with other texture, or make sprite work without reference to texture?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: About sprites.
« Reply #1 on: March 16, 2014, 10:43:07 am »
Your description is quite confusing. What do you actually want to achieve (not how)? You can use sf::Image if you want to manipulate the raw pixels, and that includes composing one image of many others.

Changing a texture is not expensive per se, please don't believe myths without context. What is expensive is copying, but usually you do this once.

And you should not use new and delete without a good reason, see also here.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

jammer312

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: About sprites.
« Reply #2 on: March 16, 2014, 10:48:02 am »
Using many textures also eats memory I think, and also
Quote
Using as few textures as possible is a good strategy, and the reason is simple: changing the current texture is an expensive operation for the graphics card. Drawing many sprites that use the same texture will give you the best performances.
It's quote from official tutorial.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: About sprites.
« Reply #3 on: March 16, 2014, 10:53:26 am »
Yes, but you shouldn't exaggerate. A difference will be noticeable if you draw thousands or millions of sprites (and then you should use vertex arrays anyway).

Again: what do you want to achieve? Why don't you compose the texture in advance in an external image editor, so you don't have to do it programmatically?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

jammer312

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: About sprites.
« Reply #4 on: March 16, 2014, 10:59:22 am »
I trying to implement it with AS, so game will be easily moddable. For it each entity needs it's own texture file

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10835
    • View Profile
    • development blog
    • Email
AW: About sprites.
« Reply #5 on: March 16, 2014, 09:04:52 pm »
If each entity type has its own texture with all their animation images then that's okay and should work fine for mostly any 2D game.
If you however mean that every single entity holds a texture, then your design is flawed and you should look into utilizing a resource holder class. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/