SFML community forums
Help => Graphics => Topic started by: wvtrammell on June 05, 2010, 05:30:16 pm
-
May I use a variablet o define the color instead of the actual Color in the App.Draw Circle command?
Warren
-
If I am reading this correctly, then yes it is perfectly possible to say (for example)
sf::Color red(255, 0, 0);
sf::Shape circle = sf::Shape::Circle(0, 0, 20, red);
-
Thanks for your advice. I guess I did not program correctly for I get an error saying "red is not a recognized color.
Apparently I am not defining the variable name I am using correctly?
Waarren
-
When I finally defined the variable properly it works great,
Thanks for your help.
-
This worked great so I decided to use it in an IF statement (enclosed).
It compiles but is ignored in execution.
What am I doing wrong please?
Warren
#include <SFML/Graphics.hpp>
int main()
{
int x = 150, y = 450, random = 5;
// Create main window
sf::RenderWindow App(sf::VideoMode(1400, 900), "SFML Graphics");
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
//Escape key exit
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
//F1 key pressed
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::F1))
App.Close();
}
// Clear screen
App.Clear(sf::Color(128, 128, 128));
sf::Color grn(0,255,0);
if(random == 5)
{
sf::Color grn(255,215,0);
}
App.Draw(sf::Shape::Circle(x,y,50,sf::Color(grn)));
// Finally, display the rendered frame on screen
App.Display();
}
return EXIT_SUCCESS;
}
-
Here you define a new variable with the same name, but which lives only in the scope of your if {}.
sf::Color grn(0,255,0);
if(random == 5)
{
grn = sf::Color(255,215,0);
}
App.Draw(sf::Shape::Circle(x,y,50,grn));