SFML community forums

Help => Graphics => Topic started by: Maxomann on April 28, 2013, 10:31:36 pm

Title: Drawing a child class of sf::Sprite
Post by: Maxomann on April 28, 2013, 10:31:36 pm
I programmed a child class of sf::Sprite which overrides the Sprites draw function.

TextBox.h
class TextBox : virtual private sf::Sprite
{

        sf::Text m_text;

public:

        virtual void draw( sf::RenderTarget& target, RenderStates states ) const;

};
 

TextBox.cpp
void TextBox::draw( sf::RenderTarget& target, RenderStates states )const
{
        //Here I want to draw the Sprites content

        target.draw( this->m_text, states );
};
 

How can I draw the Sprites content in the function?
Title: Re: Drawing a child class of sf::Sprite
Post by: Nexus on April 29, 2013, 12:18:16 am
class TextBox : virtual private sf::Sprite
Inheriting sf::Sprite is a bad idea, not to mention virtually and privately :o
Do you actually know what these keywords mean in that context?

You want a TextBox class that contains a sf::Sprite as a member. See here  (http://en.sfml-dev.org/forums/index.php?topic=10423.msg71799#msg71799) for an example on how to write a draw() function.