我正在按照在线教程学习如何编码和制作视频游戏,但我的问题是该教程已有 7 年历史,有些说明会出现问题,即使我崩溃并尝试复制示例代码也是如此直接。
更具体地说,我的问题来自于尝试在我的圈子中着色,因为它说该函数不接受 3 个参数,并且最后有一个“检查窗口是否打开”函数,它说“事件标识符未声明”,我也不确定该函数的用途。
int main()
{
sf::RenderWindow window(sf::VideoMode(1000, 1000), "Round Bounce");
//Circles
sf::CircleShape circleRed(int 100);
sf::CircleShape circlePink(int 100);
sf::CircleShape circleWhite(int 100);
//Colors
//THIS IS WHERE MY ISSUE IS.
//I used to have these formatted as (255, 0, 0));
circleRed.setFillColor(sf::Color(FF0000));
circlePink.setFillColor(sf::Color(FF8282));
circleWhite.setFillColor(sf::Color(FFFFFF));
//Location
float xPink = 200;
float yPink = 200;
float xWhite = 300;
float yWhite = 300;
circleRed.setPosition(100, 100);
circlePink.setPosition(xPink, yPink);
circleWhite.setPosition(xWhite, yWhite);
//Open Check
while (window.isOpen())
{
//THIS IS THE OTHER LOCATION I'M HAVING TROUBLES WITH
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(circleRed);
window.draw(circlePink);
window.draw(circleWhite);
window.display();
}
return 0;
}
C2660 'sf::Shape:setFillColor':function does not take 3 arguments
C2065 'Event':Undeclared Identifier
最佳答案
我在所提供的代码中看到了 2 个错误,在列出的错误中看到了另一个错误。
在sf::CircleShape circleRed(int 100);
中,int
后面的两行不属于参数。所以这些行应该是:
sf::CircleShape circleRed(100);
sf::CircleShape circlePink(100);
sf::CircleShape circleWhite(100);
然后下面的 circleRed.setFillColor(sf::Color(FF0000));
根据 documentation 颜色格式不正确.
circleRed.setFillColor(sf::Color(0xFF,0x00,0x00));
circlePink.setFillColor(sf::Color(0xFF,0x82,0x82));
circleWhite.setFillColor(sf::Color(0xFF,0xFF,0xFF));
由于数字是以十六进制给出的,因此您可以使用 0x
继续它们,请参阅此处了解更多信息:Why are hexadecimal numbers prefixed with 0x?
还有如下错误
C2065 'Event':Undeclared Identifier
表示 sf::Event
的标题不包括在内。添加
#include <Event.hpp>
在包含 main.cpp 文件的顶部。
关于c++ - 无法解决 C2660 和 C2065 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57517928/