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

Author Topic: Change color when hovering over text  (Read 4778 times)

0 Members and 1 Guest are viewing this topic.

AdrianHEY

  • Newbie
  • *
  • Posts: 14
    • View Profile
Change color when hovering over text
« on: April 14, 2021, 08:52:06 pm »
I tried to chance a text's color when hovering over it with the mouse but it gives me an error:
"error C4996: 'sf::Text::setColor': was declared deprecated"
This is the code:
void textColorRed() {
                if (sf::Mouse::getPosition().x > button.getGlobalBounds().left && sf::Mouse::getPosition().x < button.getGlobalBounds().left + button.getGlobalBounds().width)
                {
                        if (sf::Mouse::getPosition().y > button.getGlobalBounds().top && sf::Mouse::getPosition().y < button.getGlobalBounds().top + button.getGlobalBounds().height) {
                                button.setColor(sf::Color::Red);
                        }
                }
        }
Any idea what I did wrong?
PS: The two if's work because I tried to count in the console "1" and it works so I did something wrong with the color I think.
« Last Edit: April 14, 2021, 08:56:11 pm by AdrianHEY »

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: Change color when hovering over text
« Reply #1 on: April 15, 2021, 01:25:11 am »
your compiler is warning you that this function is not recomended anymore. this is because Text::setColor was divided into Text::setOutlineColor and Text::setFillColor. try the last one.
Visit my game site (and hopefully help funding it? )
Website | IndieDB

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Change color when hovering over text
« Reply #2 on: April 15, 2021, 10:13:34 am »
By the way, this should just be a warning (maybe an error if you treat warnings as errors), you can still use setColor().
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything