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

Author Topic: [Solved] Shape alpha color alter other colors?  (Read 2418 times)

0 Members and 1 Guest are viewing this topic.

Regen

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
[Solved] Shape alpha color alter other colors?
« on: September 07, 2012, 02:21:45 pm »
There is probably some easy answer to this but i have not found any answers around here.

So I have this random color, m_color. R/G/B is set 0-255 and A is always 255.
I have a shape that is set to this:
m_shape = Shape::Circle(0, 0, m_size, m_color, m_wall, Color(0, 0, 0));

This works great! But at a certain point I want to shape to fade away. So I do this from time to time when i update:
m_color.a -= 5;
m_shape.SetColor(m_color); //TODO: check why they change color?!?
 

Sooo, as you can see by my comment, the color is changing, this only happens the first time I run the code above, afterwards the shape is fading away in a nice way.
It looks like it's allways changing into a darker color?

My background color is all white, alpha = 255.

Anyone have any idea? I could add all the code here if you want, I just thought this would be enough to start with.
« Last Edit: September 07, 2012, 06:53:54 pm by Regen »
Why can't things just work?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Shape alpha color alter other colors?
« Reply #1 on: September 07, 2012, 02:26:39 pm »
The color that you pass to Shape::Circle and the color that you pass to SetColor are not the same. They are modulated (multiplied) to produce the final color.

You should leave the default color (white) in Shape::Circle, and only use SetColor.
Laurent Gomila - SFML developer

Regen

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
Re: Shape alpha color alter other colors?
« Reply #2 on: September 07, 2012, 02:34:12 pm »
Worked perfectly:) Thanks a lot!

Is there any easy answer to why they are modulated? why it is made this way?
Why can't things just work?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Shape alpha color alter other colors?
« Reply #3 on: September 07, 2012, 05:14:03 pm »
Each point of the shape has its own color, the fact that Shape::Circle only takes one is a shortcut, it assigns this color to every point. If you want you can later change the color of each individual point.

Then there's the global color of the entity, inherited from sf::Drawable. This one is modulated with the texture/color/whatever of the entity. It works the same for sprites and strings.

By the way, these classes have changed a lot in SFML 2, and things work differently.
Laurent Gomila - SFML developer

 

anything