I am trying to make a simple function or class that selects an image and returns it or passes it in some way to a different class. Is it as simple as knowing what type the Image is considered? or do I need to do something else? I am running Code::Blocks 10.05 with GNU GCC compiler on a windows 8 computer. Any help is appreciated.
Thanks to Aesthete, I made some progress. Now I have this:
class Background{
sf::Image BGI;
sf::Sprite BG;
Image& img;
public:
void rimage(std::string name){
sf::Image extra;
extra.LoadFromFile(name);
img = extra;
}
void init(std::string name){
BGI = img
BG.SetPosition(0.f,0.f);
BG.SetImage(BGI);
}
};
But when I run it, I get this:
...4 error: ISO C++ forbids declaration of 'Image" with no type
Also,
...10 error: 'img' is defined in this scope
I have included the libraries that I need to run SFML, I just left it out to keep things clean, I adjusted the lines the errors above occurred on to make it easier to follow.
Isn’t img now sort of a global variable within Background?
and I thought Image& was the type of img… What needs to change here?
You don’t need a
loadmethod, nor any extraImageobjects. You can do all this processing in the constructor.