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 - dacox

Pages: [1]
1
Graphics / Re: Overriding sf::Drawable::draw
« on: May 16, 2021, 02:44:56 pm »
@kojack
Absolute legend, thank you so much, can't believe I missed that.

2
Graphics / Overriding sf::Drawable::draw
« on: May 16, 2021, 01:53:41 pm »
I'm very new to SFML, so please be gentle,

I have a Particle class that I want to make drawable, so I want it to inherit sf::Drawable and override the draw function so that I can use window.draw(myClass). However, when I try to instantiate a particle from the class, Visual Studio tells me that "pure virtual function "sf::Drawable::draw" has no overrider" even though I've followed everything the docs said. I've dug through some similar questions on this forum already, as well as a couple of stackoverflow questions, and nothing has helped - either I've already done whatever the response suggests doing or the original asker didn't have the same problem as me.
Here's the relevant part of Particle.cpp:
void Particle::draw(sf::RenderWindow& window, sf::RenderStates states) const {
        window.draw(body);
}
 

Here's Particle.h:
class Particle : public sf::Drawable {
public:
        void update();
        void show();
        Particle();
        float getMass();
       

private:
        float x;
        float y;
        float radius;
        sf::CircleShape body;
        void draw(sf::RenderWindow& window, sf::RenderStates states) const;
};

and here's the relevant part of main.cpp:
        sf::RenderWindow window(sf::VideoMode(800, 800), "qinetiq");

        Particle particle1 = Particle();

        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(particle1);

Any and all help is massively appreciated, this is my first post on this forum, so if I'm doing something wrong please let me know.

Pages: [1]