I'm a beginner testing out manipulating sprites by testing the code from
http://sfml-dev.org/tutorials/1.6/graphics-sprite.php Besides the use of texture instead of image, it is a direct copy/paste.
class Missile
{
public :
static bool Init(const std::string& ImageFile)
{
return Texture.loadFromFile(ImageFile);
}
Missile()
{
Sprite.setTexture(Texture); // every sprite uses the same unique image
}
private :
static sf::Texture Texture; // shared by every instance
sf::Sprite Sprite; // one per instance
};
And calling if through a statement in the game loop ...
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Space)
{
Missile Bullet;
Bullet.Init("spike.png");
}
The class definition is fine, but once I call it, I receive this error:
Undefined symbols for architecture x86_64:
"Missile::Texture", referenced from:
Missile::Init(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in main.o
Missile::Missile() in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Searching around for solutions, I attempted to add the class name before the function prototypes/definitions (static bool Missile::Init(const std::string& ImageFile)) even though it is inside the class already .... of course I get an extra qualification error. Is this a linker issue? I am using mac OSX 10.8, Xcode 5.
Thanks in advance for the help, it is very much appreciated.