SFML community forums

Help => Graphics => Topic started by: kingcools on July 03, 2012, 06:29:45 pm

Title: Why is my class not drawn?
Post by: kingcools on July 03, 2012, 06:29:45 pm
Hello,

i got the following class:

class abc
:public sf::drawable,public error
{
public:
//something
void draw(blabla)const;
}

as you can see the class abc inheris from sf::drawable and error. The class error does not have a draw function(and it's no class that should be drawn, it just does some errormanagement), but when i inherit from the error class, abc stops getting drawn(which it correctly is, if i do not inherit from the error class).

So what do i do to change this? Does my error class have to inherit from sf::drawable as well? oO

Hmm, guess i should just add that error class as a member instead of inheriting...
Title: Re: Why is my class not drawn?
Post by: eXpl0it3r on July 03, 2012, 06:58:21 pm
It has to be something in your code, because the following minimal example works fine with me...

#include <SFML/Graphics.hpp>

class Foo
{
public:
        Foo() {}
};

class Bar : public sf::Drawable, public Foo
{
public:
        Bar() : Drawable(), Foo(), mRect(sf::Vector2f(10, 10)) {}
        void draw(sf::RenderTarget &target, sf::RenderStates states) const { target.draw(mRect, states); }

private:
        sf::RectangleShape mRect;
};

int main()
{
        sf::RenderWindow window(sf::VideoMode(1024, 768), "Hello");
        Bar test;

        while(window.isOpen())
        {
                test.draw(window, sf::RenderStates::Default);
       
                window.display();
        }


        return 0;
}
Title: Re: Why is my class not drawn?
Post by: kingcools on July 03, 2012, 10:02:41 pm
ok, thank you, i will look further into it
Title: Re: Why is my class not drawn?
Post by: Celtic Minstrel on July 06, 2012, 03:41:55 am
Hmm, guess i should just add that error class as a member instead of inheriting...
I think I'd recommend this... why on earth are you inheriting from error anyway?
Title: Re: Why is my class not drawn?
Post by: kingcools on July 07, 2012, 05:49:17 am
to give my class an error log ability ;)