Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - SomeUser1111

Pages: [1]
1
Graphics / Re: Shape objects as class member not drawing?
« on: December 28, 2021, 12:50:56 pm »
Thank you so much for your reply. I just didn't know how classes work, that's embrassing. :-[

2
Graphics / [Solved]Shape objects as class member not drawing?
« on: December 28, 2021, 12:09:37 pm »
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();
        }
}
 

Pages: [1]
anything