SFML community forums

Help => Graphics => Topic started by: Michalus on July 19, 2013, 02:12:34 pm

Title: SFML best objekt for drawing
Post by: Michalus on July 19, 2013, 02:12:34 pm
I want to make draw method, for a GameObject, but I dont want to give a pointer to the RenderWindow, because I can in the RenderWindow set for example the size, too.
have SFML a Class with that, I can draw something, or must I made a class myself?
Title: Re: SFML best objekt for drawing
Post by: eXpl0it3r on July 19, 2013, 03:59:07 pm
I don't really get what you want to do.
SFML can draw everything that derives from sf::Drawable, which includes sf::Sprite, sf::RectangleShape and a few others. Next to that it can draw sf::VertexArray or just an array of sf::Vertex.

So if you have already an object, but don't want to pass the window itself, then you could derive that object from sf::Drawable and implement the draw function. So you could do window.draw(myObject).
Title: Re: SFML best objekt for drawing
Post by: solver on July 19, 2013, 10:03:43 pm
Just make your GameObject deriving from sf::Drawable, and implement draw method. Somethin like this (dont afraid, it is java):
@Override
public void draw(RenderTarget target, RenderStates states) {
    target.draw(sprite, states);
    drawBoundingBox(target, states);
}
Title: AW: SFML best objekt for drawing
Post by: eXpl0it3r on July 19, 2013, 10:05:31 pm
Not sure how Java code will help a C++ programmer. :D
Rather read the tutorial. ;)
Title: Re: SFML best objekt for drawing
Post by: solver on July 19, 2013, 11:11:54 pm
In this case, no matters what language to use. I just want to show how can be draw method implemented. You know that better than me, so you can show it in c++.
Title: Re: SFML best objekt for drawing
Post by: eXpl0it3r on July 19, 2013, 11:46:46 pm
I don't have to, since everything is neatly explained in the official tutorials (http://www.sfml-dev.org/tutorials/2.0/graphics-vertex-array.php#creating-a-sfml-like-entity), which everyone should read before asking how to properly use SFML. ;)