For the past two days I have been trying to create a bullet class which can then be used to let the player fire bullets.
I have been struggling to get the bullet class to use the same image that only has to load once instead of loading it every time a bullet is created, but this leads to some problems.
I had a look in the 1.6 sprites tutorial:
http://www.sfml-dev.org/tutorials/1.6/graphics-sprite.php , specifically the Images and Sprite management section, more specifically, this piece of code:
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 do not understand this part:
static bool Init(const std::string& ImageFile)
{
return Image.LoadFromFile(ImageFile);
}
I understand the rest of the class, but I am not sure what I am meant to do with this function, do I use it after I have created the bullet?
Missile missile1;
missile1.Init("Missile.png");
Like so? Because if I just copy the Missile class exactly into my code (I wouldn't normally do this but I've been working on it for a while now), and then try to just create a Missile, I get this error:
error LNK2001: unresolved external symbol "private: static class sf::Image Missile::Image" (?Image@Missile@@0V0sf@@A)
Here is my program that produces the problem:
#include <SFML/Graphics.hpp>
class Missile
{
public :
static bool Init(const std::string& ImageFile)
{
return Image.LoadFromFile(ImageFile);
}
Missile()
{
Sprite.SetImage(Image);
}
private :
static sf::Image Image;
sf::Sprite Sprite;
};
int main()
{
sf::RenderWindow App(sf::VideoMode(640, 480), "Space Shooter");
App.SetFramerateLimit(60);
Missile missile1;
while (App.IsOpened())
{
sf::Event Event;
while (App.PollEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
}
App.Clear(sf::Color::White);
App.Display();
}
return 0;
}
Any help would be greatly appreciated, and as a side note, I'm using SFML 2.0.