301
Graphics / Re: Highlighting a sprite when mouse left clicks it
« on: June 02, 2015, 07:41:03 am »
For highlighting, I modified the color of the sprite.
So, by default a Sprite's color is solid black (0, 0, 0, 255), right? I change the color to be (128, 128, 128, 255), and call that my "base" color. That's a pretty standard grey. So your sprite will be a bit lighter when drawn than when you made it in a paint program, so you'll want to take that into account. Then, when I want to make the sprite show as highlighted, I add to it's current color by a certain amount. For me, I found adding by (40, 40, 40, 0) to look decent. I called this value my "color change".
For example, for a Button class I made:
Work decent enough for my purposes at least. Just another suggestion.
So, by default a Sprite's color is solid black (0, 0, 0, 255), right? I change the color to be (128, 128, 128, 255), and call that my "base" color. That's a pretty standard grey. So your sprite will be a bit lighter when drawn than when you made it in a paint program, so you'll want to take that into account. Then, when I want to make the sprite show as highlighted, I add to it's current color by a certain amount. For me, I found adding by (40, 40, 40, 0) to look decent. I called this value my "color change".
For example, for a Button class I made:
const sf::Color COLOR_CHANGE = {40, 40, 40, 0};
const sf::Color BASE_COLOR = {128, 128, 128};
Button::Button(...)
{
sprite.setColor(BASE_COLOR);
}
// when I want it to be highlighted
sprite.setColor(BASE_COLOR + COLOR_CHANGE);
// "unhighlight" it
sprite.setColor(BASE_COLOR);
// on press
sprite.setColor(BASE_COLOR - COLOR_CHANGE);
// unpress
sprite.setColor(BASE_COLOR);
const sf::Color BASE_COLOR = {128, 128, 128};
Button::Button(...)
{
sprite.setColor(BASE_COLOR);
}
// when I want it to be highlighted
sprite.setColor(BASE_COLOR + COLOR_CHANGE);
// "unhighlight" it
sprite.setColor(BASE_COLOR);
// on press
sprite.setColor(BASE_COLOR - COLOR_CHANGE);
// unpress
sprite.setColor(BASE_COLOR);
Work decent enough for my purposes at least. Just another suggestion.
![Smiley :)](https://www.sfml-dev.org/forums/Smileys/default/smiley.gif)