【问题标题】:Stretch sf::Sprite across entire window在整个窗口中拉伸 sf::Sprite
【发布时间】:2015-07-24 02:01:59
【问题描述】:

我有一个 sf::Sprite,当将它绘制到窗口时,我希望它填满整个窗口。

sf::RenderWindow.draw 采用可选的 sf::RenderStates。这是我需要解决的问题吗?

【问题讨论】:

  • 这能回答你的问题吗? Resizing in SFML 2.0
  • @EmileBergeron 这个问题差不多 6 岁了 idk
  • 这是一个自动评论,因为我意识到它应该被标记为重复(因为我的答案与另一个问题相同)。
  • @EmileBergeron 确定将其标记为 dup 然后
  • 它已经完成了(我只能投票),这就是自动评论的来源。这是一个奇怪的功能,我知道...

标签: c++ sfml


【解决方案1】:

首先,教程中的basic Sprite usage

取自我在Resizing in SFML 2.0 上的回答,顺便说一句,这是搜索“sfml sprite fill the screen”时的第一个谷歌结果。

首先,这是一种将图像缩放到当前 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);

如果您正在寻找背景,最优雅的方法可能是定义一个 sf::VertexArray,它将使用正确的纹理坐标渲染填充窗口的四边形。

这取自第二个谷歌结果:What happened to sprite::setSize in SFML2?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多