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

Author Topic: Drawing a child class of sf::Sprite  (Read 1175 times)

0 Members and 1 Guest are viewing this topic.

Maxomann

  • Newbie
  • *
  • Posts: 1
    • View Profile
Drawing a child class of sf::Sprite
« 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?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Drawing a child class of sf::Sprite
« Reply #1 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 for an example on how to write a draw() function.
« Last Edit: April 29, 2013, 12:21:35 am by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything