SFML community forums
Help => Graphics => Topic started by: coding99 on May 31, 2012, 05:54:37 pm
-
(http://uploadpic.org/storage/2011/thumb_WHQjVaXkbHVtKNJiS1gBLHK.png) (http://uploadpic.org/v.php?img=S8V3Q6Egzx)
this is my image(png format).
at center of image is my character(red color) and have a transparency background.
how to detect if mouse over my character(red color) not include over transparency background.
ps.sorry for my poor english.
-
Which version of SFML?
-
version 1.6
-
Get the pixel under the mouse position and check the alpha channel of that pixel.
-
thank you :)
-
What would the answer have been for sfml 2.0?
I'm sure I could be doing it better than the way I currently am.
-
With SFML 2 you would have to store a "collision map" (a 2D array of booleans), created after you load the texture, because you can't easily read from a sf::Texture.
-
The (likely worse) way that I was doing is just checking if mouse x and y lied between the min and max x and y values of the sprite's rectangle... is that pretty bad or is it alright?
-
It's not good ar bad, it depends on what you want. If an approximate detection using the sprite's rectangle is all that you need then it's perfect, if you need a more precise detection then you'll have to play with the alpha channel of the image.