SFML community forums

Help => General => Topic started by: AdrianHEY on April 14, 2021, 08:52:06 pm

Title: Change color when hovering over text
Post by: AdrianHEY 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.
Title: Re: Change color when hovering over text
Post by: Stauricus 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.
Title: Re: Change color when hovering over text
Post by: Nexus 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().