SFML community forums
Help => General => Topic started by: Natulyre on March 29, 2011, 10:22:05 pm
-
Hi there, I'm kind of puzzled. I've been trying to Increment a sprite's specific color (R, G, B) with an input. Is there anyway to do so?
Basically I'd want the sprite's color to go through the following change (R+1, G, B).
I looked at the docs and they seem to be public data members of the color class but Color is a private member of drawables, there has to be a way to do this somehow...
if (App.GetInput().IsKeyDown(sf::Key::Down)) Sprite.SetColor(Iamconfused);
Thanks in advance.
-
1. Get the sprite's color and store it in a variable
2. Change its red value
3. Set the sprite's color again (reading the variable)
If you often need this, implement a function for that task.
-
I think you want to interpolate (increment during a fixed time, if my english is bad) ?
you can do something like :
WHILE running:
WHILE there is event:
IF event.Type == KeyPressed:
action = TURN INTO RED
colororigin = currentcolor
during = 5 ; // seconds
IF action = TURN INTO RED:
color.r = color.r + ( redcolor.r - color.r ) / 5 * elapsed time since last interpolation
.....
or make an object to interpolate values.
I think i've made a mistake, it's 22:47 and never used it, so be careful and rewrite it ^^ .
-
2. Change its red value
That's actually what I'm having a hard time with.
-
I think you want to interpolate (increment during a fixed time, if my english is bad) ?
My code example isn't really useful at all my bad, I understand what you're trying to explain though. Don't worry =)
Snip
or make an object to interpolate values.
I think i've made a mistake, it's 22:47 and never used it, so be careful and rewrite it ^^ .
That seems quite interesting, I'll give it a try
-
Just read the documentation (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Color.htm). r is a public member that can be changed. Afterwards, invoke sf::Sprite::SetColor().
-
Yikes, Thanks for the help!
I just found out my oh so stupid mistake. I was trying to skip a few steps while trying to change the R component. It all makes sense to me now. Yay =)