SFML community forums

Help => Graphics => Topic started by: wvtrammell on June 05, 2010, 05:30:16 pm

Title: Variables in App.Draw
Post 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
Title: Variables in App.Draw
Post by: TheBoff on June 05, 2010, 09:07:59 pm
If I am reading this correctly, then yes it is perfectly possible to say (for example)

Code: [Select]

sf::Color red(255, 0, 0);
sf::Shape circle = sf::Shape::Circle(0, 0, 20, red);
Title: Variables in App.Draw
Post by: wvtrammell on June 06, 2010, 10:22:36 pm
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
Title: Variables in App.Draw
Post by: wvtrammell on June 10, 2010, 05:49:49 pm
When I finally defined the variable properly it works great,
Thanks for your help.
Title: Variables in App.Draw
Post by: wvtrammell on June 29, 2010, 09:53:30 pm
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

Code: [Select]
#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;
}
Title: Variables in App.Draw
Post by: Laurent on June 29, 2010, 10:51:53 pm
Here you define a new variable with the same name, but which lives only in the scope of your if {}.

Code: [Select]
     sf::Color grn(0,255,0);  
      if(random == 5)
      {
         grn = sf::Color(255,215,0);
      }
   
      App.Draw(sf::Shape::Circle(x,y,50,grn));