Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: The Last Three Points of my shape will not Change Colour  (Read 1466 times)

0 Members and 1 Guest are viewing this topic.

Idea

  • Newbie
  • *
  • Posts: 3
    • View Profile
The Last Three Points of my shape will not Change Colour
« on: January 08, 2012, 01:33:30 am »
Hello, I am new to SFML, so please excuse any questions that have obvious answers. The problem is that only the first point of the shape changes colour while the rest simply sticks to the last colour (which in this case is green) declared in the code.

Here's my code
Code: [Select]

while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
            if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Num1))
                Player.SetPointColor(0,sf::Color::Blue);
                Player.SetPointColor(1,sf::Color::Blue);
                Player.SetPointColor(2,sf::Color::Blue);
                Player.SetPointColor(3,sf::Color::Blue);

            if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::R))
                Player.SetPointColor(0,sf::Color::White);
                Player.SetPointColor(1,sf::Color::White);
                Player.SetPointColor(2,sf::Color::White);
                Player.SetPointColor(3,sf::Color::White);

            if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Num2))
                Player.SetPointColor(0,sf::Color::Red);
                Player.SetPointColor(1,sf::Color::Red);
                Player.SetPointColor(2,sf::Color::Red);
                Player.SetPointColor(3,sf::Color::Red);

            if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Num3))
                Player.SetPointColor(0,sf::Color::Green);
                Player.SetPointColor(1,sf::Color::Green);
                Player.SetPointColor(2,sf::Color::Green);
                Player.SetPointColor(3,sf::Color::Green);
        }

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
The Last Three Points of my shape will not Change Colour
« Reply #1 on: January 08, 2012, 09:44:32 am »
In C++, which I assume you are using, ifs with more than 1 line inside must have brackets, like this:

Code: [Select]
           if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Num1)) {
                Player.SetPointColor(0,sf::Color::Blue);
                Player.SetPointColor(1,sf::Color::Blue);
                Player.SetPointColor(2,sf::Color::Blue);
                Player.SetPointColor(3,sf::Color::Blue);
            }

The way you did it, only the first line after each if is conditional, all the others happens every time.

Idea

  • Newbie
  • *
  • Posts: 3
    • View Profile
The Last Three Points of my shape will not Change Colour
« Reply #2 on: January 08, 2012, 02:34:56 pm »
Quote from: "Tex Killer"
In C++, which I assume you are using, ifs with more than 1 line inside must have brackets, like this:

Code: [Select]
           if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Num1)) {
                Player.SetPointColor(0,sf::Color::Blue);
                Player.SetPointColor(1,sf::Color::Blue);
                Player.SetPointColor(2,sf::Color::Blue);
                Player.SetPointColor(3,sf::Color::Blue);
            }

The way you did it, only the first line after each if is conditional, all the others happens every time.


Thanks, the tutorials didn't really make that clear.

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
The Last Three Points of my shape will not Change Colour
« Reply #3 on: January 08, 2012, 07:05:27 pm »
You should be looking at C++ tutorials, not SFML.

 

anything