To check if the mouse is over a sprite, you want to check if the mouse's position is
greater than the sprite location and
less than the sprite's location plus its size. So a function for that may look like this:
bool MouseOverSprite( int SprID )
{
int X1 = dbSpriteX( SprID );
int Y1 = dbSpriteY( SprID );
int X2 = X1 + dbSpriteWidth( SprID );
int Y2 = Y1 + dbSpriteHeight( SprID );
if ( dbMouseX( ) > X1 && dbMouseY( ) > Y1 &&
dbMouseX( ) < X2 && dbMouseY( ) < Y2 )
return true;
else
return false;
}
This code is untested but should so what you want. It can also be compressed a lot but I wanted to keep it clear.
As for checking if the mouse is in a rectangle, that method is very similar to the one above, except you have to provide the position and size:
bool MouseOverRect( int X, int Y, int Width, int Height )
{
int X1 = X;
int Y1 = Y;
int X2 = X + Width;
int Y2 = Y + Height;
if ( dbMouseX( ) > X1 && dbMouseY( ) > Y1 &&
dbMouseX( ) < X2 && dbMouseY( ) < Y2 )
return true;
else
return false;
}
Oh, and Dark Inferno Studios was talking about dbPickObject( ), however that's only used when picking objects in 3D and it looks like you want 2D.