SFML community forums

Help => Graphics => Topic started by: texus on December 31, 2011, 04:46:35 pm

Title: Calling SetScale inside Render function
Post by: texus on December 31, 2011, 04:46:35 pm
Suppose I have a class derived from sf::Drawable.
Is there an easy way to change the scale inside the Render function?

This would be the code to create, scale and draw the object:
Code: [Select]
Object obj;
obj.Scale(2, 2);
window.Draw(obj);

And this is where the problem lies:
Code: [Select]
void Object::Render(sf::RenderTarget& target, sf::Renderer& renderer) const
{
    // I want to change the scale here!
    SetScale(4, 4);
}

I have found a way to do this by using a second class also derived from sf::Drawable and let that class take care of the drawing.
But I was wondering if there isn't an easier way to accomplish this.

I am using SFML2.
Title: Calling SetScale inside Render function
Post by: Laurent on December 31, 2011, 05:12:15 pm
Use a recent SFML 2, there's no problem with the new graphics API.
Title: Calling SetScale inside Render function
Post by: texus on December 31, 2011, 07:01:55 pm
I just downloaded the latest snapshot and I changed my code a little bit (the class is now also derived from sf::Transformable), but the problem is still the same.

Code: [Select]
void Draw(sf::RenderTarget& target, sf::RenderStates states) const
{
    SetScale(4, 4);
}

When using these lines I still get this error: "passing ‘const Object’ as ‘this’ argument of ‘void sf::Transformable::SetScale(float, float)’ discards qualifiers"
I am using Code::Blocks with gcc v4.5.2

I do understand what the error means, I am asking if there is a workaround.
Title: Calling SetScale inside Render function
Post by: texus on December 31, 2011, 08:08:00 pm
It took some time to get used to the new Draw function but I solved my problem now by using the RenderStates.

Thanks for the quick response you gave me.