无法解决 C2660 和 C2065 错误

Can't solve C2660 and C2065 Errors

我正在按照在线教程学习如何编码和制作视频游戏,但我的问题是该教程已有 7 年历史,有些说明存在问题,即使我崩溃并尝试复制直接示例代码。

更具体地说,我的问题来自尝试在我的圈子中涂色,因为它说该函数不接受 3 个参数,最后有一个 "check to see if the window is open" 函数,它表示 "Event identifier is undeclared" 而且我也不确定该函数的用途。

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的header。添加

#include <Event.hpp>

在包含 main.cpp 的 cpp 文件的顶部。