在SFML窗口中,Sprite图像被剪掉了。

问题描述 投票:0回答:1

我正在使用这本名为 "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: 添加了图像

我看到的是:(抱歉,我的截图工具在开启时似乎无法工作)enter image description here

原图。enter image description here

c++ sfml
1个回答
0
投票

你的笔记本没有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)));
© www.soinside.com 2019 - 2024. All rights reserved.