Creating buttons for a menu

Creating a button is very simple: Just add a Sprite object with 3 animations:

  • In animation 0, put an image of the button.
  • In the second animation, put an image of the hovered button.
  • Finally, in the third animation, put an image of the pressed button.

Then, using the events, just check if the cursor is on the button and if the mouse left button is being clicked, and change the animation accordingly:

There is a more advanced example called “Buttons.gdg” bundled with GD: In particular, you can use groups to generalize these events to all your buttons.