Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » How to click on a string

This thread is locked; no one can reply to it. rss feed Print
How to click on a string
Benji8
Member #16,037
August 2015

Hi! I'm trying to write a game using Allegro 4. I would like to make the game start when I click on the string "New Game" but I can't find the functions to do so in the manual. I have already written the code which installs the mouse and writes the string in the center of the screen.
Can somebody help me please?
Thank you very much!!

GullRaDriel
Member #3,861
September 2003
avatar

There isn't code because it's up to you to build something or use an existing gui library.

So, let's say your "New game" text drawing/bitmap is of size textw and texth, and that the starting point of that same "New game" is at X,Y.

When the mouse click is caught, just check if the mouse pointer coordinates are inside the box. Assuming you got them assigned in mouse_x and mouse_y, here is some pseudo code:

if( mouse_click && mouse_x >= X && mouse_y >= Y && mouse_x <= (X+textw) && mouse_y <= (Y+texth) )
{
   /* start the game as the user have clicked on new game */
}

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Benji8
Member #16,037
August 2015

Ok! It works now! thank you very much!!

GullRaDriel
Member #3,861
September 2003
avatar

You're welcome :-)

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Go to: