我正在使用一本叫做“ C ++游戏编程入门”的书来学习游戏编程。 以下是该书的摘录,它们在SFML窗口中显示了第一个游戏的背景。 (为使用命名空间而道歉,我只是在关注这本书)。
#include <SFML/Graphics.hpp>
using namespace sf;
int main()
{
RenderWindow window(VideoMode(1920, 1080), "Timber!!", Style::Fullscreen);
Texture textureBackground;
textureBackground.loadFromFile("graphics/background.png");
Sprite spriteBackground;
spriteBackground.setTexture(textureBackground);
spriteBackground.setPosition(0,0);
while (window.isOpen())
{
if (Keyboard::isKeyPressed(Keyboard::Escape)) {
window.close();
}
window.clear();
window.draw(spriteBackground);
window.display();
}
return 0;
}
我面临的问题是我在loadFromFile中尝试的图像没有完全显示在窗口中。即使我使用与图像分辨率相同的窗口大小,它也会朝左上方放大显示。
任何帮助/建议都值得赞赏。干杯!
编辑:添加了图像
答案 0 :(得分:0)
您的笔记本电脑的分辨率为1980x1080。设置可用的分辨率。然后更改view以适合整个图片:
Vector2f textureSize(1980, 1080); // or texture.getSize()
VideoMode videomode(1980, 1080);
if (!videomode.isValid()) {
videomode = VideoMode::getDesktopMode();
}
RenderWindow window(videomode, "Timber!!", Style::Fullscreen);
window.setView(View(FloatRect(0, 0, textureSize.x, textureSize.y)));