I'm following an online tutorial to learn how to code and make video games, but my problem is the tutorial is about 7 years old and some of the instructions give issues, even when I break down and try copying the sample code directly.
More specifically, my issue comes from trying to color in my circles, as it says the function doesn't take 3 arguments, and there is this "check to see if the window is open" function at the end that says the "Event identifier is undeclared" and I'm also not sure the function's purpose.
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
There are 2 bugs that I see in the code as presented and one other bug in the listed errors.
In sf::CircleShape circleRed(int 100);
and the 2 lines following the int
does not belong with the parameter. So those lines should be:
sf::CircleShape circleRed(100);
sf::CircleShape circlePink(100);
sf::CircleShape circleWhite(100);
Then below in the circleRed.setFillColor(sf::Color(FF0000));
the color format is not correct according to the documentation.
circleRed.setFillColor(sf::Color(0xFF,0x00,0x00));
circlePink.setFillColor(sf::Color(0xFF,0x82,0x82));
circleWhite.setFillColor(sf::Color(0xFF,0xFF,0xFF));
Since the numbers are given in hex you proceed them with 0x
see here for more info: Why are hexadecimal numbers prefixed with 0x?
Also the following error
C2065 'Event':Undeclared Identifier
indicates that the header for sf::Event
is not included. Add
#include <Event.hpp>
at the top of the cpp file containing main.