SFML community forums

Help => General => Topic started by: Ashmor on July 16, 2019, 08:50:02 pm

Title: Mouse events
Post by: Ashmor on July 16, 2019, 08:50:02 pm
Hey guys. I'm new to programming and to SFML. I have a little problem. I have three square sprites, s1, s2, and s3. I want them to change color when i move the cursor toward them. For example, i touch the cursor to the s1 sprite and it changes its color to green. How can i accomplish it? Could you help me out please?
Title: Re: Mouse events
Post by: Hapax on July 16, 2019, 09:40:41 pm
You can test 'collision' of a sprite and the mouse by comparing the sprite's bounding rectangle and the mouse's current position.

Testing a point inside a rectangle can be done with this:
https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Rect.php#a45c77c073a7a4d9232218ab2838f41bb
Title: Re: Mouse events
Post by: Ashmor on July 16, 2019, 10:11:26 pm
Thank you!