SFML community forums

Help => Graphics => Topic started by: rajhansk on August 31, 2017, 08:26:35 pm

Title: How Do I change color of my object every second like gradient
Post by: rajhansk on August 31, 2017, 08:26:35 pm
How Do I change color of my object every second like gradient,

I have a circle and I want to change its color with every second it passes.
Which function should I use ??

Any help will be appreciated.

Thank you
Title: Re: How Do I change color of my object every second like gradient
Post by: Hapax on August 31, 2017, 09:45:59 pm
To change/set the colour of a circle (or any standard SFML shape), use: setFillColor(sf::Color)

To animate the colour, change the colour depending on the time given by a clock (you can use sf::Time and sf::Clock (https://www.sfml-dev.org/tutorials/2.4/system-time.php)).

For a small example of animating values smoothly depending on time, you can take a look at this animation of the SFML logo (https://github.com/Hapaxia/SfmlLogoAnimation).
In particular, you might find most use of this section of code (https://github.com/Hapaxia/SfmlLogoAnimation/blob/master/SfmlLogoAnimation/SfmlLogoAnimation.cpp#L220-L229).
Title: Re: How Do I change color of my object every second like gradient
Post by: rajhansk on September 01, 2017, 06:28:08 am
Thanks