SFML community forums

Help => Graphics => Topic started by: Dennis on February 18, 2017, 03:08:33 pm

Title: Drawing is too hard in sfml?
Post by: Dennis on February 18, 2017, 03:08:33 pm
When i want to draw a simple rectangle i have to create an object for every single rectangle or draw the same object on multiple places is there any other way i can draw.

when i create a class with a draw function i can't just enter  window->draw_rectangle(x,y,width,height) i must create an object inside the class and set all its properties inside the constructor.

i can try to use the same object and change the value's before drawing it but there is no pop() or push() so i would have to reset everything manually.





 :-\
Title: Drawing is too hard in sfml?
Post by: eXpl0it3r on February 18, 2017, 03:13:47 pm
SFML is more an object oriented library, however it's fairly easy to create a function/class that would more work the way you want.

Also C++ by itself is often more object oriented and less a functional programming language, so I suggest to adapt your logical thinking, rather than trying to force your model onto the language. ;)
Title: Re: Drawing is too hard in sfml?
Post by: Laurent on February 18, 2017, 03:20:37 pm
There are just too many options in each drawable class, to replace them with a single drawing function. There would be too many arguments, and you would probably have to set all of them, even the ones you don't care about.

Using drawing functions also means that you must store the drawing parameters on your side, so using classes helps you write less code by aggregating these parameters into single objects.

And of course if you really like drawing with functions rather than objects, you can easily write the corresponding functions yourself, with only the arguments that are relevant in your context.

void drawSomeStuff(sf::RenderTarget& target, arg1, arg2, arg3, ...)
{
    sf::SomeDrawable drawable;
    drawable.setStuff1(arg1);
    drawable.setStuff2(arg2);
    drawable.setStuff3(arg3);
    ...
    target.draw(drawable);
}