将SF :: Sprite伸展整个窗户
Stretch sf::Sprite across entire window
我有一个sf :: sprite,当它绘制到窗口时,我希望它填充整个窗口。
sf :: renderwindow.draw采用可选的SF :: Renderstates。那是我需要弄乱的吗?
首先,教程中的基本sprite用法。
从我自己的回答SFML 2.0中提取的答案,顺便说一句,这是搜索" SFML Sprite填充屏幕"时的第一个Google结果。
首先,这是一种将图像扩展到当前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);
请注意,如果纵横比不是 保持。您可能需要添加代码以调整您的决定 案例。
然后,如果要拉伸渲染窗以填充所有屏幕, 我可以建议您使用全屏模式吗?
这是完成方式的片段:
// 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,这将使用正确的纹理坐标填充窗口,从而使四边形填充窗口。
这是从第二个Google结果中获取的:Sprite :: Setsize在SFML2中发生了什么?
相关文章:
- 如何在窗户上使用和配置叮当声?
- 使用 sf::Text 数组时崩溃
- 尝试将 sf::Texture* 推送到 std::vector 时出错
- 为什么 sf::Text 显示点而不是数字?
- 从 c++ 运行 MsiExec.exe?窗户
- sf::文本不显示?
- sf::Windows上的音乐:api-ms-win-crt-locale-l1-1-0.dll:无法打开共享对象文件
- 如何将sf::RenderWindow传递给另一个函数
- 当我尝试绘制 sf::Text 对象时,SFML 中的分段错误
- 管道到窗户上的ffmpeg
- 重载运算符时出错<在 sf::Vector 中
- 声明 sf::SoundBuffer 会导致程序在终止时崩溃
- 如何为我的窗户腾出顶部空间?
- 正在加载 sf::图片来自 QDialog
- SFML 中的分段错误 调用 sf::窗口::关闭后
- 在窗户中编译CUDA的意义
- 窗户的C BLE中央开发
- 未解决的外部符号sf ::带有SFML的时间
- 在离开模式下唤醒窗户
- 将SF :: Sprite伸展整个窗户