SFML community forums
Help => Graphics => Topic started 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
-
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).
-
Thanks