我正在使用这本名为 "Beginning C++ game programming "的书来学习,嗯,游戏编程.下面是书中的一个片段,它在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中尝试的图片都不能完全显示在窗口中。即使我使用与图像分辨率相同的窗口大小,它也会显示在左上方。
任何帮助建议都是感激的。干杯!
EDIT: 添加了图像
你的笔记本没有1980x1080的分辨率。设置可用的分辨率。然后改变 观点 以适应全局。
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)));