What am I doing wrong?
Why does this work
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "wtf");
window.setVerticalSyncEnabled(true);
const unsigned int NumberOfPlayers = 4;
sf::CircleShape Players[NumberOfPlayers];
// Puttin the 'setRadius' inside this for makes it work
for(unsigned int i = 0; i<NumberOfPlayers; i++)
{
Players[i].setRadius(50);
Players[i].setPosition({i*100, 0});
}
while (window.isOpen())
{
window.clear(sf::Color::Black);
for(auto player : Players)
window.draw(player);
window.display();
}
return 0;
}
and this doesn't?
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "wtf");
window.setVerticalSyncEnabled(true);
const unsigned int NumberOfPlayers = 4;
sf::CircleShape Players[NumberOfPlayers];
// This doesn't work!
for(auto player : Players)
{
player.setRadius(50);
}
// Puttin the 'setRadius' inside this for makes it work
for(unsigned int i = 0; i<NumberOfPlayers; i++)
{
Players[i].setPosition({i*100, 0});
}
while (window.isOpen())
{
window.clear(sf::Color::Black);
for(auto player : Players)
window.draw(player);
window.display();
}
return 0;
}
The change is the location of 'setRadius' in the code. The second snippet results in a blank window.
Thanks