staticbool Init(const std::string& ImageFile)
Sprite.SetImage(Image); // every sprite uses the same unique image
static sf::Image Image; // shared by every instance
sf::Sprite Sprite; // one per instance
What this code seems to say is load the image into a static variable, then every time an object is made it will use the same static image and thus you've saved memory as you don't have to load the image every time.
However, in trying to replicate this, I've come across the issue. Surely the "Init()" function has to be called before the constructor? How would I go about doing this, if at all, as surely the point of a constructor is that it's called first?
Thanks for that, seems to have partially resolved my problem, but now when I try to compile I get the following:
/tmp/ccdrmEHx.o: In function `Missile::init(std::string&)':
missile.cpp:(.text._ZN7Missile4initERSs[_ZN7Missile4initERSs]+0x14): undefined reference to `Missile::image'
/tmp/ccdrmEHx.o: In function `Missile::Missile()':
missile.cpp:(.text._ZN7MissileC2Ev[_ZN7MissileC5Ev]+0x1e): undefined reference to `Missile::image'
collect2: error: ld returned 1 exit status
(I renamed 'Image' to 'image' because using uppercase gave a compiler warning).