SFML community forums

Help => Graphics => Topic started by: dotty on January 22, 2012, 07:34:31 pm

Title: Is it possible to draw FloatRects to the screen?
Post by: dotty on January 22, 2012, 07:34:31 pm
As the title suggests, I'm using FloatRects for some collision detection. Is it possible to draw these to the screen so I can see their positions? I know I could simple copy the attributes of said FlaotRect then create a Shape, but I'm wondering if it's possible without the need of using Shape.

Thanks!
Title: Is it possible to draw FloatRects to the screen?
Post by: julen26 on January 22, 2012, 07:38:19 pm
If you are using SFML 2 you can use sf::Vertex class. If not, I think that sf::Shape is the unique option (unless you use openGl directly).
Title: Is it possible to draw FloatRects to the screen?
Post by: Elgan on January 22, 2012, 07:45:03 pm
sf::RectangleShape
?
Title: Is it possible to draw FloatRects to the screen?
Post by: julen26 on January 22, 2012, 07:56:30 pm
Quote from: "Elgan"
sf::RectangleShape
?


Omg, I have not noticed about that class until now :lol:
Sorry, anyway it's a sf::Shape based class.
Title: Is it possible to draw FloatRects to the screen?
Post by: dotty on January 22, 2012, 08:21:46 pm
but RectangleShape doesn't have the methods like Intersect and Contains though.
Title: Is it possible to draw FloatRects to the screen?
Post by: texus on January 22, 2012, 08:35:26 pm
Quote
but RectangleShape doesn't have the methods like Intersect and Contains though.

Just use your FloatRect for collision detection and create a RectangleShape from it when drawing:

Code: [Select]
sf::RectangleShape shape(sf::Vector2f(rect.Width, rect.Height));
shape.SetPosition(rect.Left, rect.Top);
window.Draw(shape);
Title: Is it possible to draw FloatRects to the screen?
Post by: dotty on January 22, 2012, 08:39:14 pm
I guess that's the only way to do it. Ok, thanks.