SFML community forums

Help => General => Topic started by: Natulyre on March 29, 2011, 10:22:05 pm

Title: Color Incrementing
Post 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...

Code: [Select]

if (App.GetInput().IsKeyDown(sf::Key::Down))  Sprite.SetColor(Iamconfused);


Thanks in advance.
Title: Color Incrementing
Post by: Nexus on March 29, 2011, 10:44:51 pm
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.
Title: Color Incrementing
Post by: danman on March 29, 2011, 10:47:27 pm
I think you want to interpolate (increment during a fixed time, if my english is bad) ?

you can do something like :
Code: [Select]

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 ^^ .
Title: Color Incrementing
Post by: Natulyre on March 29, 2011, 10:48:11 pm
Quote from: "Nexus"

2. Change its red value


That's actually what I'm having a hard time with.
Title: Color Incrementing
Post by: Natulyre on March 29, 2011, 10:50:05 pm
Quote from: "danman"
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 =)

Code: [Select]

Snip

Quote from: "danman"

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
Title: Color Incrementing
Post by: Nexus on March 29, 2011, 10:50:30 pm
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().
Title: Color Incrementing
Post by: Natulyre on March 29, 2011, 10:57:47 pm
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 =)