What is the best way to group objects in SFML?

0

If I have for example 3 different shapes in SFML, and I want to rotate all in relation to a single center, as if these 3 shapes were inside a square, what would be the best shape? Would it be leaving them inside a view and rotating the view? Or is there some more practical way?

    
asked by anonymous 25.04.2018 / 22:14

1 answer

1

Apparently, for all I've seen, the simplest and most intuitive way is to put the objects inside the view.

For example:

  RectangleShape background (Vector2f(windowWidth, windowHeight)); // draw a full rectangle to show the container dimensions
    background.setFillColor(Color::White);

    RectangleShape r1 (Vector2f(100,100)); // 1st object
    r1.setFillColor(Color::Red);
    r1.setPosition(Vector2f(30,10));


    RectangleShape r2 (Vector2f(150,200)); // 2nd object
    r2.setFillColor(Color::Blue);
    r2.setPosition(Vector2f(120,160));


    while (window.isOpen())
    {
        Event event;
        while (window.pollEvent(event))
        {
            if (event.type == Event::Closed)
                window.close();
        }

        window.clear();
        window.setView(view);
        window.draw(background);
        window.draw(r1);
        window.draw(r2);
        view.setRotation(30); // affects all elements

        window.display();
    }

    return 0;
}

    
26.04.2018 / 02:00