SFML provides us with the functionality to draw basic shapes such as a rectangle, circle, and triangle. The shape can be set to a certain size and has functions, such as fillColor, Position, and Origin, so that we can set the color, the position of the shape in the viewport, and the origin around which the shape can rotate respectively. Let's take a look at an example of a rectangular shape:
- Before the while loop, add the following code to set up the rectangle:
sf::RectangleShape rect(sf::Vector2f(500.0f, 300.0f)); rect.setFillColor(sf::Color::Yellow); rect.setPosition(viewSize.x / 2, viewSize.y / 2); rect.setOrigin(sf::Vector2f(rect.getSize().x / 2,
rect.getSize().y / 2));
Here, we created a Rectangle parameter of the RectangleShape type and named it rect. The constructor of RectangleShape takes in the size of the rectangle. Its size...