SFML community forums

Help => Graphics => Topic started by: jammer312 on March 16, 2014, 10:38:57 am

Title: About sprites.
Post by: jammer312 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?
Title: Re: About sprites.
Post by: Nexus 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 (http://www.bromeon.ch/articles/raii.html).
Title: Re: About sprites.
Post by: jammer312 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.
Title: Re: About sprites.
Post by: Nexus 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?
Title: Re: About sprites.
Post by: jammer312 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
Title: AW: About sprites.
Post by: eXpl0it3r 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. ;)