SFML Window 调整大小非常难看
SFML Window Resizing is very ugly
当我调整我的 sfml window 大小时,当我剪切调整大小以使其变小并调整大小以使其变大时,它会给您带来非常奇怪的效果。
如何使调整大小更漂亮?代码来自code::blocks的安装教程。
代码(与sfml网站code::blocks的安装教程中的代码相同):
#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;
}
您需要管理 window 的大小调整。否则坐标是错误的。这是您的代码和解决方案的摘录。感谢本论坛的作者post,这是我在寻找解决方案时曾经找到它的地方:https://en.sfml-dev.org/forums/index.php?topic=17747.0
此外,您还可以根据新尺寸设置新坐标。 link 为您提供更多信息。
// 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 window 大小时,当我剪切调整大小以使其变小并调整大小以使其变大时,它会给您带来非常奇怪的效果。
如何使调整大小更漂亮?代码来自code::blocks的安装教程。 代码(与sfml网站code::blocks的安装教程中的代码相同):
#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;
}
您需要管理 window 的大小调整。否则坐标是错误的。这是您的代码和解决方案的摘录。感谢本论坛的作者post,这是我在寻找解决方案时曾经找到它的地方:https://en.sfml-dev.org/forums/index.php?topic=17747.0
此外,您还可以根据新尺寸设置新坐标。 link 为您提供更多信息。
// 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
}
}