SFML的窗口调整非常丑陋

问题描述 投票:0回答:1

当我调整sfml窗口的大小时,当我剪切调整大小使其变小,调整大小使其变大时,它给你的效果非常奇怪。A cut out green circleA "laser beam" coming out from the green circle

怎样才能让调整大小更漂亮呢?这段代码来自code::block.Code的安装教程(与sfml网站上code::block的安装教程中的代码相同)。

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

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

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}
c++ sfml
1个回答
2
投票

你需要管理窗口的大小调整。否则坐标是错误的。下面是你的代码与解决方案的节选。归功于本论坛帖子的作者,这是我曾经在寻找解决方案时发现的。https:/en.sfml-dev.orgforumsindex.php?topic=17747.0。

另外你可以根据新的尺寸设置新的坐标。链接给你更多的信息。

// create own view
sf::View view = window.getDefaultView();

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

        if (event.type == sf::Event::Resized) {
            // resize my view
            view.setSize({
                    static_cast<float>(event.size.width),
                    static_cast<float>(event.size.height)
            });
            window.setView(view);
            // and align shape
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.