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

Author Topic: Mouse events  (Read 1340 times)

0 Members and 1 Guest are viewing this topic.

Ashmor

  • Newbie
  • *
  • Posts: 6
    • View Profile
Mouse events
« 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?

Hapax

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

Ashmor

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Mouse events
« Reply #2 on: July 16, 2019, 10:11:26 pm »
Thank you!