无法解决 C2660 和 C2065 错误

Can't solve C2660 and C2065 Errors

本文关键字:C2065 错误 C2660 解决      更新时间:2023-10-16

我正在按照在线教程学习如何编码和制作视频游戏,但我的问题是该教程大约有 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::形状:设置填充颜色':函数不接受 3 个参数
C2065 "事件":未声明的标识符

我在显示的代码中看到 2 个错误,在列出的错误中看到另一个错误。

sf::CircleShape circleRed(int 100);int后面的 2 行不属于参数。所以这些行应该是:

sf::CircleShape circleRed(100);
sf::CircleShape circlePink(100);
sf::CircleShape circleWhite(100);

然后在下面的circleRed.setFillColor(sf::Color(FF0000));根据文档,颜色格式不正确。

circleRed.setFillColor(sf::Color(0xFF,0x00,0x00));
circlePink.setFillColor(sf::Color(0xFF,0x82,0x82));
circleWhite.setFillColor(sf::Color(0xFF,0xFF,0xFF));

由于数字以十六进制给出,因此您可以使用它们0x请参阅此处以获取更多信息:为什么十六进制数字以 0x 为前缀?

还有以下错误

C2065 "事件":未声明的标识符

指示不包括sf::Event的标头。加

#include <Event.hpp>

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