1
Graphics / Multiple sprites with static image
« on: July 13, 2009, 11:36:09 pm »
I am trying to get this bit of example code I found to work, but i'm not exactly sure how to use it.
I have that included in my code, but how would I create an object of that type? Its constructor calls Sprite.SetImage(Image), but the Init function is what sets the Image. I'm not sure how to set the Image with the Init function before the constructor is called. Or is there some other way I should be going about setting the Image for the object?
Code: [Select]
class Missile
{
public :
static bool Init(const std::string& ImageFile)
{
return Image.LoadFromFile(ImageFile);
}
Missile()
{
Sprite.SetImage(Image); // every sprite uses the same unique image
}
private :
static sf::Image Image; // shared by every instance
sf::Sprite Sprite; // one per instance
};
I have that included in my code, but how would I create an object of that type? Its constructor calls Sprite.SetImage(Image), but the Init function is what sets the Image. I'm not sure how to set the Image with the Init function before the constructor is called. Or is there some other way I should be going about setting the Image for the object?