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

Author Topic: [solved]Drawable Class  (Read 2475 times)

0 Members and 1 Guest are viewing this topic.

ElChupacabra

  • Newbie
  • *
  • Posts: 7
    • View Profile
[solved]Drawable Class
« on: October 25, 2008, 03:26:43 am »
Hi guys,
Can you maybe help me with this? How do I create a class which I can hand over to the sf::RenderWindow::Draw() function? Lets say my class consists of drawable objects like sf::String and sf::Shape. In other words what I want to do is:
Code: [Select]

class myButton
{
  Shape shape;
  String string;
  myButton(..stuff) { ... stuff}
};
int main()
{
  RenderWindow App();
  myButton button();
  App.Draw(button);
...
}

Imbue

  • Full Member
  • ***
  • Posts: 104
    • View Profile
[solved]Drawable Class
« Reply #1 on: October 25, 2008, 04:05:02 am »
Give this a try.

Code: [Select]
class myButton : public sf::Drawable
{
    public:
        myButton() {}

    private:
        sf::Shape shape;
        sf::String string;

        virtual void Render(sf::RenderTarget& Window) const
        {
            Window.Draw(shape);
            Window.Draw(string);
        }
};


BTW, this will also give your button lots of other methods like SetPosition() etc. SFML handles all that automatically. :D

ElChupacabra

  • Newbie
  • *
  • Posts: 7
    • View Profile
[solved]Drawable Class
« Reply #2 on: October 26, 2008, 08:18:15 pm »
Thanks for the answer, looks good. But I keep getting the message "`RenderTarget' has not been declared". I use Codeblocks on windows. System.hpp,Window.hpp and Graphics.hpp are included.
It works however when I redefine the Render function this way:
Code: [Select]
protected: virtual void Render(const RenderWindow &Window) const

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[solved]Drawable Class
« Reply #3 on: October 26, 2008, 08:31:41 pm »
RenderTarget is for SVN (next) version.
Laurent Gomila - SFML developer

 

anything