SFML community forums
Help => Graphics => Topic started 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:
Object obj;
obj.Scale(2, 2);
window.Draw(obj);
And this is where the problem lies:
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.
-
Use a recent SFML 2, there's no problem with the new graphics API.
-
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.
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.
-
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.