Something which I could not find in the XNA framework, but which whilst working with 2D textures for in example menu’s is something you would definately want to see to make your life easier. To prevent myself from having to write the same stuff over and over, checking if a mouseclick was made within the [...]
Something which I could not find in the XNA framework, but which whilst working with 2D textures for in example menu’s is something you would definately want to see to make your life easier. To prevent myself from having to write the same stuff over and over, checking if a mouseclick was made within the X and Y of the texture rectangle of the button or field I have written the following function:
bool IsInRect(int x, int y, Rectangle rect)
{
if ((x >= rect.Left) &
(x <= rect.Right) &
(y >= rect.Top) &
(y <= rect.Bottom))
return true;
return false;
}
The function is quite easy to understand, you simply pass on a value for x, in example from msMouseState and do the same for y. Last but not least you pass on the rectangle you want to compare it with, now if the x and y values are located within the rectangle true is returned, otherwise it will return a false.
A simple sollution, but very effective :).
