Convex Shapes in SFML

In this post, I would like to talk about the use of Convex Shapes in SFML. ConvexShape class is already a built-in structure in SFML. All we have to do is specify the corner points of the shape as a programmer. Let's create a convexshape as an example:

ConvexShape convexShape = new ConvexShape(4);

convexShape.SetPoint(0, new Vector2f(40, 100));
convexShape.SetPoint(1, new Vector2f(300, 100));
convexShape.SetPoint(2, new Vector2f(220, 150));
convexShape.SetPoint(3, new Vector2f(20, 170));
As above, four points are defined for the convexshape. According to these points, the following result was obtained on the screen:
ConvexShape in SFML
We can give a different color to this shape or add a texture if we want. I want to add texture. I used 256x256 size image as texture and I got the result like this:
ConvexShape with Texture

No comments:

Post a Comment