[英]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.