Here is my full code:
const int windowWidth = 500;
const int windowHeight = 400;
class Box
{
public:
RectangleShape shape;
Box(float size_a, float size_b)
{
shape.setFillColor(Color::Blue);
shape.setPosition(100, 100);
shape.setSize({ size_a, size_b });
shape.setOutlineThickness(2);
shape.setOutlineColor(Color::Black);
}
};
int main()
{
Box box(200,150);
RenderWindow window(VideoMode(windowWidth, windowHeight), "Box");
window.setFramerateLimit(60);
while (window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
if (event.type == Event::Closed)
window.close();
}
window.clear(Color::White);
window.draw(box.shape);
window.display();
}
return 0;
}
Get the following:
If I change constructor:
Box(float size_a, float size_b)
{
shape.setOrigin(100, 100);
shape.setFillColor(Color::Blue);
shape.setPosition(150, 150);
shape.setSize({ size_a, size_b });
shape.setOutlineThickness(2);
shape.setOutlineColor(Color::Black);
shape.setRotation(20);
}
Produce this:
Top-left corner moving coordinates (x-100,y-100), and rotate relative to top-left corner.