SFML community forums
Help => Graphics => Topic started by: Shadowblitz16 on October 23, 2019, 01:33:43 am
-
why isn't there a sf::LineShape() and sf::EllipseShape() in the sfml graphics library?
these are really basic shapes that should be added for ease of use.
I come from love2d where drawing a line is as simple as love.graphics.line(x1,y1,x2,y2) and a ellipse is as simple as love.graphics.ellipse(drawmode,x,y,xr,yr); and setting the width of a line shape is as easy as.. love.graphics.setlinewidth(width);
anyways missing these just doesn't sound simple or fast can they be added?
-
There's no shape class for lines. The reason is simple: If your line has a thickness, it is a rectangle. If it doesn't, it can be drawn with a line primitive.
- Shapes tutorial (Built-in shape types (https://www.sfml-dev.org/tutorials/2.5/graphics-shape.php#built-in-shape-types) - under "Lines")
It also shows you how to draw them.
In that very Shapes tutorial, in the Custom Shape Types (https://www.sfml-dev.org/tutorials/2.5/graphics-shape.php#custom-shape-types) section, you can find a complete Ellipse shape type.
A number of other shapes can added on top of the sf::Shape base. It has restrictions though. Mainly, it's a triangle fan so cannot create all shapes, especially if it's concave or has a hole in it (like a ring).
Any other shape can be created using a vertex array (https://www.sfml-dev.org/tutorials/2.5/graphics-vertex-array.php).
Some things have already been created to save you from having to do it yourself. Selba Ward (https://en.sfml-dev.org/forums/index.php?topic=19496.0), for example, is a collection of drawables that can reduce the amount of stuff you have to create yourself. It includes lines and polylines (Spline (https://github.com/Hapaxia/SelbaWard/wiki/Spline)), which would replace any need for you to make your own line class, especially since it does connected lines, thick lines, and Bezier curved lines 8)
-
this still is inconvenient for something that is suppose to be simple and fast.
also vertices don't have collision properties so they shouldn't be used as a tutorial for a line shape.
-
I am not sure what's so inconvenient about copying that Ellipse code into a file or copying the class you want from Selba Ward (https://github.com/Hapaxia/SelbaWard/wiki) into your project. They're also pretty "simple" and "fast" ways to do it, since you keep wanting to focus on those words.
I am unsure about your point about collision. None of the built-in shapes have collision other than it being able to work out its own axis-aligned boundary box, you can do this for any set of vertices easily. This, of course, means that even using an sf::CircleShape would require to do your own collision code so it's best to write all your own collision code.
Eveything I've said aside, feel free to insist further and get a response from the SFML team that will tell you that it will not be added. There have been a number of discussions about this on this forum already and if you have a look, you will see the valid reasons why they won't.