Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Color Incrementing  (Read 2648 times)

0 Members and 1 Guest are viewing this topic.

Natulyre

  • Newbie
  • *
  • Posts: 6
    • View Profile
Color Incrementing
« 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.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Color Incrementing
« Reply #1 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

danman

  • Hero Member
  • *****
  • Posts: 1121
    • View Profile
    • Email
Color Incrementing
« Reply #2 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 ^^ .
Pointilleur professionnel

Natulyre

  • Newbie
  • *
  • Posts: 6
    • View Profile
Color Incrementing
« Reply #3 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.

Natulyre

  • Newbie
  • *
  • Posts: 6
    • View Profile
Color Incrementing
« Reply #4 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

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Color Incrementing
« Reply #5 on: March 29, 2011, 10:50:30 pm »
Just read the documentation. r is a public member that can be changed. Afterwards, invoke sf::Sprite::SetColor().
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Natulyre

  • Newbie
  • *
  • Posts: 6
    • View Profile
Color Incrementing
« Reply #6 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 =)

 

anything