SFML community forums

Help => Graphics => Topic started by: jmpeer on May 02, 2010, 11:26:20 pm

Title: virtual void Render(RenderTarget& Target)
Post by: jmpeer on May 02, 2010, 11:26:20 pm
Yo,
I made a class called Button.
It inherits from String, but also has an Image and Sprite member.
I assumed if I wanted my RenderWindow to draw the Sprite and then the String,
I needed this in the .hpp file:
Code: [Select]
protected:
virtual void Render(RenderTarget& Target);

And this in the .cpp file:
Code: [Select]
void Render(RenderTarget& Target)
{
     Target.Draw(sprite);
}


It draws the String, the parent class, but does nothing with the sprite, the member. What is the most appropriate way of doing this?
Title: virtual void Render(RenderTarget& Target)
Post by: gsaurus on May 02, 2010, 11:36:51 pm
This:
Quote
private:
void Render(RenderTarget& Target) const;

It is private const  :wink:
Title: virtual void Render(RenderTarget& Target)
Post by: jmpeer on May 03, 2010, 12:05:58 am
Oh, thanks.
Button is now inheriting from Drawable.
And it has a Sprite, Image, and String member.
And they're being drawn correctly now.
In the .hpp:
Code: [Select]
protected:
virtual void Render(RenderTarget& Target) const;

In the .cpp:
Code: [Select]
void Render(RenderTarget& Target) const
{
     Target.Draw(sprite);
     Target.Draw(text);
}