Well, that's what I did. I mean I made a function that tells my object of class Board which element to pick. And yes, I see how ugly it is
The second solution you suggested seems good and profesional. Although I'm not sure if I'm able to write it, I'll try it.
Which of them is better (quicker to execute)?
Thank you for reply
EDIT:I've changed my code a bit again so it handles displaying some of my sprites but there are still some that are appear as white shapes. Can I ask once again to tell me, where my mistake is? I tried everything, nothig worked
My code now:Board.hclass Board : public Drawable, Transformable
{
public:
bool set_up(int nrOfBoard, int level); // that method sets all sprites and loads
// from files coordinates of everything
int what_board;
private:
Texture texture; // texture of board
Sprite background; // sprite of board
struct oneBoard : public Drawable, public Transformable
{
vector<Sprite> adds;
vector<Sprite> things;
virtual void draw(RenderTarget &target, RenderStates states) const
{
for (int i = 0; i < adds.size(); i++)
target.draw(adds[i], states);
for (int i = 0; i < things.size(); i++)
target.draw(things[i], states);
}
};
vector<oneBoard> map_of_all_boards;
virtual void draw(RenderTarget &target, RenderStates states) const;
};
Board.cppbool Board::set_up(int nrOfBoard, int level)
{
// some stuff, also determining the number_of_boards
for (int i = 0; i < number_of_boards; i++)
{
Board board;
oneBoard one;
//again some stuff, determining amount_of_adds
for (int i = 0; i < amount_of_adds; i++)
{
Texture tex;
Sprite spr;
string directory;
Vector2f vec;
plik >> directory;
plik >> vec.x;
plik >> vec.y;
tex.loadFromFile(directory);
spr.setTexture(tex);
spr.setPosition(vec);
one.adds.push_back(spr);
}
// and again stuff, detrmining amount_of_things
for (int i = 0; i < amount_of_things; i++)
{
Texture tex;
Sprite spr;
string directory;
Vector2f vec;
plik >> directory;
plik >> vec.x;
plik >> vec.y;
tex.loadFromFile(directory);
spr.setTexture(tex);
spr.setPosition(vec);
one.things.push_back(spr);
}
// WEPCHNIECIE CALEGO POKOJU DO WEKTORA POKOI
map_of_all_boards.push_back(one);
plik.close();
}
}
void Board::which_board(int brd)
{
what_board = brd;
}
void Board::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.transform *= getTransform();
states.texture = NULL;
target.draw(background);
target.draw(map_of_all_boards[what_board]);
}
I tought that the way I load all that sprites can have an impact on my problem, so I decided to show you more code this time.
So my problem is: my code loads and displays proprely backgroung and loads properly sprites into adds and things. No doubt it does. But on the screen I see my background and white shapes of sprites from vectors adds and things. Any solution? Can you tell me, if part of my code is incorrect, how to fix it?
Sorry for my english