SFML community forums

Help => Graphics => Topic started by: starkhorn on April 13, 2016, 07:24:24 am

Title: Highlight sprite when selected
Post by: starkhorn on April 13, 2016, 07:24:24 am
I need some guidance on how to go about achieving the below outcome as I am at a bit of a loss on how to go about it. I am not looking for code but any pseudo-code or a general outline of the steps involved would be much appreciated.

So I can detect when my sprite is selected. What I want to do is to highlight the outline of the sprite with a specific colour which indicates that it is selected.

Also rather than having this just a static colour, is there is way to make the outline appear as shiny? Would this just involve changing the colour very quickly?

I know the above is vague but I am still new to sfml and graphics programming and I feel like I hit a bit of a wall with this one.
Title: Re: Highlight sprite when selected
Post by: Jesper Juhl on April 13, 2016, 08:00:07 am
A simple way would be to just have two images. One with the normal sprite and one with a highlight, then just draw the right one dependin on whether or not it is selected.

Another option would be to use a shader.
Title: AW: Highlight sprite when selected
Post by: eXpl0it3r on April 13, 2016, 08:01:39 am
You would probably want an outline shader. I have never done ot, but I'm sure Google can find you a GLSL shader for that.
Title: Re: Highlight sprite when selected
Post by: starkhorn on April 14, 2016, 03:24:26 am
Hi Folks,

Yeah ok doing a 2nd image with the outline is fairly straight-forward. However that is just a static image. How can I make that outline image appearing like it is flashing?
Title: AW: Highlight sprite when selected
Post by: eXpl0it3r on April 14, 2016, 11:22:25 am
You could animate it manually with multiple images etc.

Or again, a shader can do it. ;)
Title: Re: Highlight sprite when selected
Post by: Hapax on April 14, 2016, 10:27:49 pm
For coloured outlines, you could replace your sf::Sprite with textured sf::RectangleShape (they can have customised but single-colour outlines).

Since this outline can be coloured separately, it's simple to animate it separately without affecting the actual texture.