SFML 窗口大小调整非常难看 [英] SFML Window Resizing is very ugly

查看:61
本文介绍了SFML 窗口大小调整非常难看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我调整我的 sfml 窗口的大小时,当我削减 resize 以使其更小并调整其大小以使其更大时,它会给你一个非常奇怪的效果.

When I resize my sfml window, when I cut resize to make it smaller and resize to make it larger, it gives you a really weird effect.

如何使调整大小更漂亮?代码来自 code::blocks 的安装教程.代码(同sfml网站code::blocks安装教程中的代码):

How do I make the resizing more prettier? The code is from the installation tutorial for code::blocks. Code (same as the code in the installation tutorial for code::blocks on the sfml website):

#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;
}

推荐答案

您需要管理窗口的大小调整.否则坐标不对.这是带有解决方案的代码的摘录.感谢这篇论坛帖子的作者,这是我在寻找解决方案时曾经找到的地方:https://en.sfml-dev.org/forums/index.php?topic=17747.0

You need to manage the resize of the window. Otherwise the coordinates are wrong. Here is an excerpt of your code with the solution. Credits go to the author of this forum post, this is where I once found it when I was looking for a solution: https://en.sfml-dev.org/forums/index.php?topic=17747.0

此外,您可以根据新尺寸设置新坐标.该链接为您提供了更多信息.

Additionally you can set the new coordinates based on the new size. The link gives you more information.

// 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
        }
    }

这篇关于SFML 窗口大小调整非常难看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆