How I check for mouse over
BlitzMax Forums/BlitzMax Beginners Area/How I check for mouse over
| ||
I have this code I use to check if an icon is selected -> hence, if the mouse is OVER a specific area of the screen (i use this in my main loop while reading mousex() and mousey() Local x1: Int = X_of_image Local x2: Int = X_of_image+ width_of_Image Local y1: Int = Y_of_image Local y2: Int = y_of_image + height_of_image If MouseX() > x1 And MouseX() < x2 If MouseY() > y1 And MouseY() < y2 ... DO SOMETHING! WE ARE OVER THE AREA ... EndIf EndIf ' is there a smarter way? and for the standard windows mouse pointer will this trigger only, and only when the upper left corner of the mouse is within the area? |
| ||
Didn't the code here help? |
| ||
that code does the exact same thing as above as far as I can see |
| ||
that code does the exact same thing as above as far as I can see but in a smarter way .The smartest way would probably be to use colliderect. |
| ||
how is it smarter? |
| ||
You create/register your rects (or images or buttons or icons or whatever) and then simply call it once each loop. The way you've suggested to do it will make it difficult to add more checks and bloat the mainloop. |
| ||
Its smarter because the documentation says it is. Have a look! ;) |
| ||
I just created an Icon type for managing Icons in your program. I posted it in the archives if you think you can find use for it. http://www.blitzbasic.com/codearcs/codearcs.php?code=1926 |