I found that drawable objects(such as CircleShape, VertexArray...etc) cannot be drawn if they are class member. What is going wrong? Is there a problem in constructing a object?
I'm using:
SFML 2.5.1
GCC 7.3.0
This is an simple example regards the problem.
#include <SFML/Graphics.hpp>
class Class{
public:
sf::CircleShape circle;
Class(){
sf::CircleShape circle(100.f);
}
void main(){
sf::RenderWindow window(sf::VideoMode(640,480),"Title");
while(window.isOpen()){
sf::Event event;
while(window.pollEvent(event)){
if (event.type == sf::Event::Closed) window.close();
}
window.clear(sf::Color::Black);
window.draw(circle); // This does not draw
window.display();
}
}
};
int main(){
Class clazz;
clazz.main();
sf::RenderWindow window(sf::VideoMode(640,480),"Title");
while(window.isOpen()){
sf::Event event;
while(window.pollEvent(event)){
if (event.type == sf::Event::Closed) window.close();
}
window.clear(sf::Color::Black);
window.draw(clazz.circle); // This doesn't draw either
window.display();
}
}