Hey my friends I have a really big spritesheet and wanted to ask about the performance difference between loading a lot of textures from parts of it and loading the full texture one time and setting the IntRect when giving it to a sprite.
Like this pseudocode:
loadFromFile(spritesheetPath, IntRect(184, 108, 13, 16));
loadFromFile(spritesheetPath, IntRect(168, 108, 14, 18));
loadFromFile(spritesheetPath, IntRect(634, 24, 122, 25));
// and so on
vs.
loadFromFile(spritesheet);
sprite1.setTexture(spritesheet, IntRect(184, 108, 13, 16))
sprite2.setTexture(spritesheet, IntRect(168, 108, 14, 18))
sprite3.setTexture(spritesheet, IntRect(634, 24, 122, 25))
// and so on
The second method would be very inconvenient because of the way my Resource Manager is structured but I don't want do loose too much performance when loading lots of textures.
Thanks for your Answers :)
Daniel
in the first case you are loading the same texture over and over again. it's bad at loading time and probably at drawing time too (I'm saying "probably" because I don't know if internally SFML keeps copies of the textures or just many references to the same texture while loading a texture with IntRect)
use the second case, where you just load it once and point where each sprite should use it.
edit: why exactly would it be inconvenient for you? remember you can change a sprite's texture rect anytime with sprite.setTextureRect(IntRect(184, 108, 13, 16))