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

Author Topic: Highlight sprite when selected  (Read 4698 times)

0 Members and 1 Guest are viewing this topic.

starkhorn

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • Email
Highlight sprite when selected
« 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.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Highlight sprite when selected
« Reply #1 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.
« Last Edit: April 13, 2016, 08:03:40 am by Jesper Juhl »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Highlight sprite when selected
« Reply #2 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

starkhorn

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • Email
Re: Highlight sprite when selected
« Reply #3 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Highlight sprite when selected
« Reply #4 on: April 14, 2016, 11:22:25 am »
You could animate it manually with multiple images etc.

Or again, a shader can do it. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Highlight sprite when selected
« Reply #5 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*