Here is a sample of my C++ code to attempt to share a single sprite between instances of a class. I want to avoid the redundancy of having each object own a copy of the same image.
class Rock
{
public:
Rock();
int x;
int y;
Rock(int new_x, int new_y, sf::RenderWindow * the_window);
~Rock();
void update();
// hold a static sprite for all rocks
static sf::Image my_image;
static sf::Sprite my_sprite;
// hold the window to draw to
sf::RenderWindow* my_window;
};
// define static variables
????????????????????????
My problem is that sprites must be loaded when created and the static implementation wants one created on the fly. The rocks need to have an image associated with them an also that image as the sprite's image. I'm a bit new to the concept of static data so forgive me of my code is just off the wall. I'm working from a tutorial that used simple ints. The image for the sprite exists in "resources/sprites/block.png".
From my understanding of static data defined outside the class to which it belongs.
type Class::member_data = value
...
sf::Image Rock::my_image =
<- What goes here to assign a new image?