Sign in to follow this  
mybluehair

need help with mouse in allegro

Recommended Posts

mybluehair    100
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
Nerd_Skywalker    100
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
nGamer    184
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this