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

Author Topic: [Solved] Problem with sf::sprite.SetImage problem  (Read 2878 times)

0 Members and 1 Guest are viewing this topic.

Jatentaki

  • Newbie
  • *
  • Posts: 3
    • View Profile
[Solved] Problem with sf::sprite.SetImage problem
« on: May 08, 2009, 06:42:15 pm »
Code: [Select]

int temp;
fin >> temp;
if (temp == 1)
{
   if (!Image.LoadFromFile("s596.bmp"))
   {
      fout << "Error s596.bmp" << std::endl;
   }
   else
   {
      fout << "s596.bmp loaded" << std::endl;
   }
   Sprite[i][j].SetImage(Image);
}
   if (temp == 2)
  {
     if (!Image.LoadFromFile("s543.bmp"))
     {
        fout << "Error s543.bmp" << std::endl;
     }
     else
     {
        fout << "s543.bmp loaded" << std::endl;
     }
     Sprite[i][j].SetImage(Image);
}
Sprite[i][j].SetPosition(0.f+(32*j), 0.f+(32*i));


I am using this inside a loop whichs aim is to write a array of 32x32px pictures in a nice square using data from file :) As you see it reads to temp variable a number from this map file and then in one case shows first picture and in second case second picture. I am new to programming graphic things so correct me if im wrong but i think creating huge amounts of sf::image files would be a waste of RAM so i try to reuse this variable. The problem is that whole square consists of sprites of only one kind (s596.bmp). As you can see I made a nice log but it shows that both types are being loaded and there are no errors in it. Whats the problem?

1) I used search and didnt find solution
2) I changed the error/no error messages to log from polish to english but if its the cause of problems im not gonna use c++ anymore  :P

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
[Solved] Problem with sf::sprite.SetImage problem
« Reply #1 on: May 08, 2009, 07:02:17 pm »
Where is defined 'Image' ?

You may want use an ImageManager to save RAM.
SFML / OS X developer

Jatentaki

  • Newbie
  • *
  • Posts: 3
    • View Profile
[Solved] Problem with sf::sprite.SetImage problem
« Reply #2 on: May 08, 2009, 07:13:50 pm »
Code: [Select]

    sf::Image Image;
    // Create the sprite
    sf::Sprite Sprite[20][20];

Here is Sprite declaration and I will have a look at resource manager in a moment ;)

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
[Solved] Problem with sf::sprite.SetImage problem
« Reply #3 on: May 08, 2009, 07:21:46 pm »
At present time your code doesn't work the way you expect.

You have only one Image for more than one file. So the second loading will erase the first picture. And at the end, all your sprite will draw the same Image.

You have to use one sf::Image per file. Or use a Manager like mine.
SFML / OS X developer

Jatentaki

  • Newbie
  • *
  • Posts: 3
    • View Profile
[Solved] Problem with sf::sprite.SetImage problem
« Reply #4 on: May 08, 2009, 07:23:42 pm »
Ah, I forgot sprite is just a pointer to image :/ Sorry for your waste of time

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
[Solved] Problem with sf::sprite.SetImage problem
« Reply #5 on: May 08, 2009, 07:44:07 pm »
no problem  :wink:
SFML / OS X developer