• Advertisement
Sign in to follow this  

need help with mouse in allegro

This topic is 2927 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm very new to Allegro, and trying to learn. I am creating a test game, and I need to create some buttons for the user to click on with the mouse. So I drew the button to the screen (as a sprite), enabled the mouse, and tried to create a make-shift if statement to say "if the mouse is over this certain area (the button area), and the button is pressed...do this." the problem is that my code looks very tacky, and I cant really get it to detect there the button is. I think I'm going into this a$$-backward. Is there a better way to do what I'm trying to do? Thanks :) code: show_mouse(screen); draw_sprite( screen, button, 410, 215); while ( !key[KEY_ESC] ){ if(mouse_x >= 410 && mouse_x <= 430 && mouse_y >= 215 && mouse_x <= 220){ **DO THIS** } }

Share this post


Link to post
Share on other sites
Advertisement
Right now I think that is the way you should do it, but when you get more advanced, you could make a class for each button, then when ever the button updates, it checks to see if the mouse is in its bounds.

Share this post


Link to post
Share on other sites
That is how I accomplished my first collisions. It will suffice if you just beginning, however, in the future, I would suggest what Nerd_Skywalker advised.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement