Awesome answers guys, I will try to implement those things. Thank you very much
EDIT: Got it working now, you guys are awesome. Just 1 small question. It does display my sprites now but all sprites are white... just white squares!?
I am using .PNG files...
Any idea what could be wrong?
if(!texture.loadFromFile(ROOT + "levelLayout\\" + *i)){
std::cout << "FOUT" << std::endl;
} else {
std::cout << "LOAD: " << *i << std::endl;
}
Says everything was loaded succesfully, and the compiler dusnt give me any errors or what so ever.
Anyways, thanks so much for your help guys. I am ripping the code apart as we speak to learn every bit there is. Thanks again, and hopefully someone knows why my sprites are white
I am searching into "As soon as the function ends, your vectors are gone." now, since that might be the problem I guess. But since I put them (now, didnt do that before) into my private section they should keep existing at all time untill the deconstructor is called upon right?
class level {
private:
int levelNr;
bool finished;
bool nameDisplayed;
std::vector<sf::Sprite> sprites;
public:
// default constructor
level( int levelNr );
// functions
void draw(sf::RenderWindow &win);
void loadLevel(); // load level sprites
void loadNext(); // load next level
};
void level::loadLevel(){
// set a vector with all needed sprites
std::vector<std::string> name;
// name.push_back("background.png");
// name.push_back("objects_1.png");
name.push_back("objects_2.png");
// name.push_back("floor.png");
// name.push_back("platform.png");
// loop through the sprites and add them to a vector sprite
for(std::vector<std::string>::iterator i = name.begin(); i != name.end(); i++)
{
sf::Texture texture;
///////////////////////////////////////////////////////////////
if(!texture.loadFromFile(ROOT + "levelLayout\\" + *i)){
std::cout << "FOUT" << std::endl;
} else {
std::cout << "LOAD: " << *i << std::endl;
}
///////////////////////////////////////////////////////////////
sf::Sprite sprite(texture);
sprite.setPosition(100, 200);
sprites.push_back(sprite);
}
}
Update Found out whats wrong, just as I have been told they dont exist long enough. Going to fix that now