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

Author Topic: How to know what button being pressed with a procedural style  (Read 6418 times)

0 Members and 1 Guest are viewing this topic.

sangpham2710

  • Newbie
  • *
  • Posts: 1
    • View Profile
How to know what button being pressed with a procedural style
« on: November 23, 2021, 04:37:26 am »
I'm coding a minesweeper game, and in the game, there are 2 types of buttons: the cells of the board and the utility buttons like restart and save game.
I coded the game in a procedural programming style, I wanna know how do I check which kind of button is pressed and thereby trigger different actions for those buttons elegantly. Because since we only have the mouse X and Y coordinates from the mouse event, the way I tended to do it is to check whether a button has the mouse cursor in it or not when the mouse is being pressed. But this way of doing it is very clumsy and it starts being tedious when I have to do it for each of the scenes in the game.
I know you can use OOP and check every type of "clickable" object every scene but I coded mine in console in a procedural style and I don't wanna waste time changing it into OOP style.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: How to know what button being pressed with a procedural style
« Reply #1 on: November 24, 2021, 10:01:51 am »
I don't fully understand how you've set it up right now.
If you've written a long list of ifs for each button, then you might want to turn that into a loop and calculate the offsets on the fly or introduces classes that represent buttons, that have this information stored.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything