Can you tell me what exactly should I do (how to write it properly)? I don't understand why is my Base class not handling with all those objects created and pushed into vector correctly. I'm not very skilled programer.
EDIT:Ok, I've studied virtual methods and found all I knew about them wasn't true so I've learned how to handle them properly, how to override them and make them doing what I want them to do, but I met another problem and maybe it is unable to do it in a way I want to do it, but if it is possible to do, please help me with following:
That's 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
private:
Texture texture; // texture of board
Sprite background; // sprite of board
struct adds
{
Vector2f coordinates;
Sprite add;
};
struct things
{
Vector2f coordinates;
Sprite thing;
};
struct oneBoard
{
vector<adds> add_s;
vector<things> thing_s;
};
vector<oneBoard> map_of_all_boards;
virtual void draw(RenderTarget &target, RenderStates states) const;
};
Board.cppvoid Board::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.transform *= getTransform();
states.texture = NULL;
target.draw(background);
for (int i = 0; i < map_of_all_boards[0].add_s.size(); i++)
target.draw(map_of_all_boards[0].add_s[i].add, states);
for (int i = 0; i < map_of_all_boards[0].thing_s.size(); i++)
target.draw(map_of_all_boards[0].thing_s[i].thing, states);
}
As you can see I display 'map_of_all_boards[0]', the very first thing in my vector. I would like to change it and display those one which I want by changing:
virtual void draw(RenderTarget &target, RenderStates states) const;
in something like this:
virtual void draw(RenderTarget &target, RenderStates states, int board_number) const;
but I keep getting error:
error C2664: 'void sf::RenderTarget::draw(const sf::Vertex *,unsigned int,sf::PrimitiveType,const sf::RenderStates &)' : cannot convert argument 1 from 'int' to 'const sf::Drawable &'
Reason: cannot convert from 'int' to 'const sf::Drawable'
while I try to use it as following:
window.draw(Boards, 0); // Boards is an object of class Board
I understand why I get it. I only ask you now to advise me how can I display one element of my vector, how can I pass the information of which element method should pick to my overrided draw?
Any help welcome! Please, I need it fast!
Sorry for my english!