1
Graphics / Getting confusing compiler error when trying to color a rectangle.
« on: August 06, 2018, 12:55:59 pm »int main(){
sf::RenderWindow window(sf::VideoMode(800, 600), "Game");
sf::RectangleShape rectangle(sf::Vector2f(100, 50));
shape.setFillColor(sf::Color(211, 211, 211));
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear(sf::Color::Black);
window.draw(shape);
window.display();
}
sf::Music music;
if (!music.openFromFile("audio/ambwon.ogg")){}
music.setVolume(50);
music.play();
}
sf::RenderWindow window(sf::VideoMode(800, 600), "Game");
sf::RectangleShape rectangle(sf::Vector2f(100, 50));
shape.setFillColor(sf::Color(211, 211, 211));
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear(sf::Color::Black);
window.draw(shape);
window.display();
}
sf::Music music;
if (!music.openFromFile("audio/ambwon.ogg")){}
music.setVolume(50);
music.play();
}
My compiler, GNU GCC, gives me "error: 'shape' was not declared in this scope" on line 17 (shape.setFillColor(sf::Color(211, 211, 211));.
shape.setFillColor worked just fine earlier, so why is it throwing errors all of a sudden?
Any insight would be greatly appreciated.