【问题标题】:Resizing in SFML 2.0在 SFML 2.0 中调整大小
【发布时间】:2014-02-17 06:29:09
【问题描述】:

这可能是一个简单的问题,但我很难找到一个直接的答案:有没有办法在 SFML 2.0 中调整已加载纹理的大小?例如,如果我有一个 3264x2448 的 png,并且我想缩小它以适应 900x1200 的渲染窗口而不进行裁剪,我该怎么做?

【问题讨论】:

  • 除非您要求纹理可缩放,而不是简单地缩小它,否则我建议您调整实际图像的大小。它将占用更少的硬盘空间和更少的内存。如果您不断调整大图像的大小,您的应用程序的性能也可能会受到影响。
  • 有没有办法缩放所有渲染的窗口以适应运行应用程序的任何系统的任何监视器?

标签: c++ sfml


【解决方案1】:

有没有办法缩放所有渲染的窗口以适应任何显示器 应用程序在哪个系统上运行?

首先,这是一种将图像缩放到当前 RenderWindow 大小的方法。

// assuming the given dimension
// change this dynamically with the myRenderWindow->getView().getSize()
sf::Vector2f targetSize(900.0f, 1200.0f); 

yourSprite.setScale(
    targetSize.x / yourSprite.getLocalBounds().width, 
    targetSize.y / yourSprite.getLocalBounds().height);

请注意,如果不保持纵横比,这可能会拉伸您的图像。您可能需要添加代码来调整您的案例的决定。

那么,如果你想把 RenderWindow 拉伸成全屏,我建议你使用全屏模式吗?

这里是它是如何完成的sn-p:

// add the flag to the other ones
mStyleFlag = sf::Style::Default | sf::Style::Fullscreen;

// get the video mode (which tells you the size and BPP information of the current display
std::vector<sf::VideoMode> VModes = sf::VideoMode::getFullscreenModes();

// then create (or automatically recreate) the RenderWindow
mMainWindow.create(VModes.at(0), "My window title", mStyleFlag);

【讨论】:

【解决方案2】:

有没有办法在 SFML 2.0 中调整已加载纹理的大小?

不是直接sf::Texture。但是您可以使用sf::Sprite:加载加载纹理,将其传递给sf::Sprite,然后使用sf::Sprite::setScalesf::Sprite::scale

【讨论】:

    猜你喜欢
    • 2013-03-06
    • 1970-01-01
    • 2016-11-22
    • 1970-01-01
    • 2013-12-09
    • 1970-01-01
    • 2011-04-24
    • 2012-06-29
    • 1970-01-01
    相关资源
    最近更新 更多