Welcome,
Guest
. Please
login
or
register
. Did you miss your
activation email?
French forum
Home
Help
Search
Login
Register
SFML community forums
»
Help
»
Graphics
»
[solved] how to detect mouse if over a character?
Print
Pages: [
1
]
Author
Topic: [solved] how to detect mouse if over a character? (Read 3117 times)
0 Members and 1 Guest are viewing this topic.
coding99
Newbie
Posts: 5
[solved] how to detect mouse if over a character?
«
on:
May 31, 2012, 05:54:37 pm »
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.
«
Last Edit: May 31, 2012, 06:54:55 pm by coding99
»
Logged
I use SFML version 1.6 and sorry for my poor English.
- sfml1.6 can compile cleanly with gcc 4.4(recommended)-4.5 and gcc 4.6-4.7 must define NULL or modify some code
- compiling sfml1.6 with codeblocks is good on codeblocks 8.02(10.05 alway add .dll suffix)
Laurent
Administrator
Hero Member
Posts: 32498
Re: how to detect mouse if over a character?
«
Reply #1 on:
May 31, 2012, 06:12:26 pm »
Which version of SFML?
Logged
Laurent Gomila - SFML developer
coding99
Newbie
Posts: 5
Re: how to detect mouse if over a character?
«
Reply #2 on:
May 31, 2012, 06:22:29 pm »
version 1.6
Logged
I use SFML version 1.6 and sorry for my poor English.
- sfml1.6 can compile cleanly with gcc 4.4(recommended)-4.5 and gcc 4.6-4.7 must define NULL or modify some code
- compiling sfml1.6 with codeblocks is good on codeblocks 8.02(10.05 alway add .dll suffix)
eXpl0it3r
SFML Team
Hero Member
Posts: 11030
Re: how to detect mouse if over a character?
«
Reply #3 on:
May 31, 2012, 06:37:03 pm »
Get the pixel under the mouse position and check the alpha channel of that pixel.
Logged
Official FAQ:
https://www.sfml-dev.org/faq.php
Official Discord Server:
https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog:
https://duerrenberger.dev/blog/
coding99
Newbie
Posts: 5
Re: [solved] how to detect mouse if over a character?
«
Reply #4 on:
May 31, 2012, 07:00:18 pm »
thank you
Logged
I use SFML version 1.6 and sorry for my poor English.
- sfml1.6 can compile cleanly with gcc 4.4(recommended)-4.5 and gcc 4.6-4.7 must define NULL or modify some code
- compiling sfml1.6 with codeblocks is good on codeblocks 8.02(10.05 alway add .dll suffix)
vro
Newbie
Posts: 44
Re: [solved] how to detect mouse if over a character?
«
Reply #5 on:
June 03, 2012, 06:26:00 am »
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.
Logged
Laurent
Administrator
Hero Member
Posts: 32498
Re: [solved] how to detect mouse if over a character?
«
Reply #6 on:
June 03, 2012, 08:55:39 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.
Logged
Laurent Gomila - SFML developer
vro
Newbie
Posts: 44
Re: [solved] how to detect mouse if over a character?
«
Reply #7 on:
June 03, 2012, 09:45:23 am »
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?
Logged
Laurent
Administrator
Hero Member
Posts: 32498
Re: [solved] how to detect mouse if over a character?
«
Reply #8 on:
June 03, 2012, 10:41:57 am »
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.
Logged
Laurent Gomila - SFML developer
Print
Pages: [
1
]
SFML community forums
»
Help
»
Graphics
»
[solved] how to detect mouse if over a character?