SFML community forums

Help => General => Topic started by: CyanPrime on April 07, 2011, 11:20:39 am

Title: load a array of sprites using 1 sf::Image?
Post by: CyanPrime on April 07, 2011, 11:20:39 am
I want to load a array of sf::Sprites using only 1 sf::Image, and loading images to that image over and over. I don't want to create a array of images because I'm worried about ram usage. But I can't get anything to work. It aether loads every sprite as 1 image, or gives me a white box. How would I go about doing this?

edit: my code: http://pastebin.com/RW0ZeySP
Title: load a array of sprites using 1 sf::Image?
Post by: Laurent on April 07, 2011, 11:34:23 am
If you want to display N images at the same time, you need to have those N images in RAM. You can't just magically delete the loaded pixels while still displaying them on screen ;)
Title: load a array of sprites using 1 sf::Image?
Post by: CyanPrime on April 07, 2011, 11:35:35 am
But isn't the image data in the sf::Sprite object too?
Title: load a array of sprites using 1 sf::Image?
Post by: Laurent on April 07, 2011, 11:39:51 am
No. That's the reason why sf::Sprite and sf::Image are two separate classes.

sf::Image is the heavy one that holds the pixels in memory, and sf::Sprite is just a lightweight interface that describes how to draw an image. All it does is to store a pointer to the sf::Image that you give it, it doesn't copy the pixels. This way, there's no unnecessary overhead if you want to draw 1000 sprites that use the same source image.
Title: load a array of sprites using 1 sf::Image?
Post by: CyanPrime on April 07, 2011, 11:42:01 am
Oh, wow. I didn't know that! Thank you very much. you've helped me out a lot! ^_^