SFML community forums
Help => Graphics => Topic started by: bogdyby on July 31, 2017, 11:19:04 am
-
Hi guys, i want to do a card game in c++, and it didn t work very well at graphic part.
Can you tell me how i can do a clickcable picture and how i can chose a action for that button when he's pressed? I using sfml 2.4
-
When you click on a window, the operating system sends an event to that window. When you check the events in the event loop, you check for the "mouseButtonPressed" event and, if one exists, you check if the current mouse position is inside the image/sprite/button. The mouse button pressed event contains the mouse position. To do that check, get the global bounds of the image's object and then use its "contains" method to see if the mouse position is within its bounds.
More information:
Events (https://www.sfml-dev.org/tutorials/2.4/window-events.php)
Rect's Contains method (https://www.sfml-dev.org/documentation/2.4.2/classsf_1_1Rect.php#aa8a5364c84de6dd5299f833b54e31ef1)
Making sure the mouse position is in the same co-ordinates system if you are using a view (https://www.sfml-dev.org/tutorials/2.4/graphics-view.php#coordinates-conversions)