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

Author Topic: load a array of sprites using 1 sf::Image?  (Read 3415 times)

0 Members and 1 Guest are viewing this topic.

CyanPrime

  • Newbie
  • *
  • Posts: 18
    • View Profile
load a array of sprites using 1 sf::Image?
« 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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
load a array of sprites using 1 sf::Image?
« Reply #1 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 ;)
Laurent Gomila - SFML developer

CyanPrime

  • Newbie
  • *
  • Posts: 18
    • View Profile
load a array of sprites using 1 sf::Image?
« Reply #2 on: April 07, 2011, 11:35:35 am »
But isn't the image data in the sf::Sprite object too?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
load a array of sprites using 1 sf::Image?
« Reply #3 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.
Laurent Gomila - SFML developer

CyanPrime

  • Newbie
  • *
  • Posts: 18
    • View Profile
load a array of sprites using 1 sf::Image?
« Reply #4 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! ^_^

 

anything