简体   繁体   English

如何使用C ++在Visual Studio 2017中修复此TextureBackground标识符

[英]How do I fix this textureBackground identifier in Visual Studio 2017 using C++

I've experienced a problem when trying to declare an identifier. 尝试声明标识符时遇到问题。 The main part is textureBackground.loadFromFile("graphics/background.png"); 主要部分是textureBackground.loadFromFile(“ graphics / background.png”); where textureBackground is the one being underlined 其中textureBackground是下划线的

I've tried adding parentheses, changing uppercases, lower cases, check file locations, etc. 我尝试添加括号,更改大写字母,小写字母,检查文件位置等。

int main()
{
    //Create a video mode object
    VideoMode vm(1920, 1080);

    // Create and open a window for game
    RenderWindow window(vm, "Scarful!!!", Style::Fullscreen);
    while (window.isOpen())

        // Texture for graphic on cpu
        Texture textureBackground;

        // Load graphic into texture
         textureBackground.loadFromFile("graphics/background.png");

        // Make Sprite
        Sprite spriteBackground;

        // Attach texture to sprite
        spriteBackground.setTexture(textureBackground);

        // Set spritebackground to cover screen
        spriteBackground.setPosition(0, 0);
    {
        /* Handle player input */

        if (Keyboard::isKeyPressed(Keyboard::Escape))
        {
            window.close();

        }

        //Update Scene


        //Draw Scene
        window.clear();
        //Draw Game Scene
        window.draw(spriteBackground);

        //Show everything we drew
        window.display();
    }
    return 0;
}

Here, 这里,

while (window.isOpen())
    // Texture for graphic on cpu
    Texture textureBackground;
// Load graphic into texture
textureBackground.loadFromFile("graphics/background.png");

You are trying to do this: 您正在尝试这样做:

while (window.isOpen()) {
    // Variable goes out of scope outside of the loop...
    Texture textureBackground;
}
   textureBackground.loadFromFile("graphics/background.png");
// ^^^^^^^^^^^^^^^^^ is not available anymore...

And since textureBackground is out-of-scope you cannot modify it anymore... I suggest you wanted... 而且由于textureBackground不在范围内,因此您无法再对其进行修改...我建议您要...

// Texture for graphic on cpu
Texture textureBackground;

// Load graphic into texture
textureBackground.loadFromFile("graphics/background.png");

// Make Sprite
Sprite spriteBackground;

// Attach texture to sprite
spriteBackground.setTexture(textureBackground);

// Set spritebackground to cover screen
spriteBackground.setPosition(0, 0);

while (window.isOpen()) {
    // Other code goes here...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Windows 上使用 Visual Studio 2017 连接到 C++ 中的 sqlite 数据库? - How do I connect to an sqlite database in C++ using visual studio 2017 on Windows? 如何在 Visual Studio 2017 中无错误地打开 Visual Studio 2019 c++ 代码? - How do i open Visual Studio 2019 c++ code in Visual Studio 2017 without errors? 如何在 Visual Studio 2017 中为 C++ 控制台应用程序添加 header 文件 - How do I add header file for a C++ console app in Visual Studio 2017 Microsoft Visual C ++,Visual Studio,如何修复错误:标识符“ GetAsyncKeyState”未定义 - Microsoft Visual C++, Visual Studio, How to fix the error: identifier “GetAsyncKeyState” is undefined 如何使用 Visual Studio 2017 在 C++ 中为参数化对象数组使用唯一指针? - How can I use unique pointers for an array of parameterized objects in C++ using Visual Studio 2017? 如何修复这个未声明的标识符? (C++) - How do I fix this undeclared identifier? (C++) 如何修复 C++ 中未识别的 Typedef 变量错误 (Visual Studio 2017) - How to fix Typedef variable not identified error in C++ (Visual Studio 2017) 我需要哪个SDK才能确保Visual Studio C ++ 2017中的Windows 7兼容性 - Which SDK do I need to ensure Windows 7 compatibility in Visual Studio C++ 2017 在Mac上的Visual Studio社区2017中使用C ++? - Using C++ in Visual Studio Community 2017 on Mac? 如何在Visual Studio 2017 [C ++]中使用GLOP线性求解器 - How to use the GLOP Linear Solver with Visual Studio 2017 [C++]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM