SFML community forums
Help => Window => Topic started by: ElChupacabra 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:
class myButton
{
Shape shape;
String string;
myButton(..stuff) { ... stuff}
};
int main()
{
RenderWindow App();
myButton button();
App.Draw(button);
...
}
-
Give this a try.
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
-
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:
protected: virtual void Render(const RenderWindow &Window) const
-
RenderTarget is for SVN (next) version.