【发布时间】:2020-10-30 20:57:35
【问题描述】:
【问题讨论】:
-
我的第一个想法是监听
sf::Event::Resized事件,然后调用sf::Window::setSize来强制执行该比率。
【问题讨论】:
sf::Event::Resized 事件,然后调用sf::Window::setSize 来强制执行该比率。
我终于设法做我想做的事。我听sf::Event::Resized 并调用sf::Window::setSize 然后我改编了this post 的代码,看起来像这样:
// set screen size
float screenWidth = 800.f;
float screenHeight = 600.f;
// get the resized size
sf::Vector2u size = _window.getSize();
// setup my wanted aspect ratio
float heightRatio = screenHeight / screenWidth;
float widthRatio = screenWidth / screenHeight;
// adapt the resized window to my wanted aspect ratio
if (size.y * widthRatio <= size.x)
{
size.x = size.y * widthRatio;
}
else if (size.x * heightRatio <= size.y)
{
size.y = size.x * heightRatio;
}
// set the new size
_window.setSize(size);
【讨论】: