I have this:
main.cpp
#include <vector>
#include "Bola.h"
Bola B1();
std::vector <Bola> Ball;
void addBalls(); //this function is the problem
int main()
{
addBalls(); //Replace
//Here is where I draw everything
return 0;
}
void addBalls() {
Bola nB ();
Ball.push_back(nB);
Ball.back().getBall().setPosition(0, 30); //Not working
}
Bola.h
#include <SFML/Graphics.hpp>
class Bola {
sf::Texture tBall;
public:
Bola();
sf::Sprite getBall();
~Bola() {}
private:
sf::Sprite sBall;
};
Bola.cpp
#include "Bola.h"
Bola::Bola() {
tBall.loadFromFile("imgs/bola.png");
sBall.setTexture(tBall);
}
sf::Sprite Bola::getBall() {
return sBall;
}
The vector and the function addBalls() togheter are not working. If I try to add a new ball using the function it does add a new ball but the sprite does not get rendered.
if I instead add a new ball to the vector using "the same code of the function" addBalls() in the place where I call the function now the sprite gets rendered somehow.
I cant see what´s wrong.
Thanks in advance.