So for some reason, all the images I am loading for my sprites are being turned into white squares. They are at the appropriate position in space, and they even change color if I want them to, so I know they are there, but they remain nothing more than blank squares of whatever color I set them at.
The way I've done it is I have two containers, one for tile images and one for object images. Each container contains each image only once, and all instances of objects or tiles take their image from these containers. Within the constructor for the
Baby class (one of the object classes), I've included this code:
m_Sprite.SetImage(pLevel->GetMobImage(1));
m_Sprite.SetPosition(m_X, m_Y);
cout << m_X << ", " << m_Y << endl;
m_Sprite.SetColor(sf::Color(255, 0, 0));
Note that
Baby inherits from
Mob. Mob contains only the
sf::Sprite m_Sprite; declaration, however, as well as the following draw function:
void Mob::Draw(sf::RenderWindow* App)
{
App->Draw(m_Sprite);
}
Level::GetMobImage() is defined as follows:
sf::Image Level::GetMobImage(int image)
{
if (image >= m_MobImages.size())
{
cout << "ERROR! No image this far into the vector!\n";
}
return m_MobImages[image];
}
Where m_MobImages is the aforementioned container of sf::Images.
---
So, blank squares.
I first thought my code was too convoluted. Yet I am able to change the color of my sprites, and they definitely have the same size as the images they are supposed to be displaying (some are 9x9, others 15x15, others 32x32).
But then I tested out the other sf::Image using class,
Tile, and realized that the tiles that form the background of the scene are also being drawn as blank white squares, even if I give them squiggly black lines as art (I hadn't noticed until then because the tiles had always been blank, and since they did color in using sf::Sprite::SetColor, I thought all was well).
I tried an inefficient hack, just to see if I could get it to work, by having instances of
Baby have their own sf::Image data member and load its contents directly from a file themselves, without the whole container system. I did so by including the following in the constructor for
Baby:
sf::Image Image;
Image.LoadFromFile("Baby.png");
m_Sprite.SetImage(Image);
m_Sprite.SetPosition(m_X, m_Y);
m_Sprite.SetColor(sf::Color(255, 0, 0));
Again, all I get are red squares.
Can anyone point me in the right direction?
---
This was a similar post about something that seemed similar a few months ago, but reading it didn't really help me solve this, as s/he seemed to be trying to do something different than I am.
http://www.sfml-dev.org/forum/viewtopic.php?t=4493&sid=f9feaa1f0a8d93be858aed89b385873a