How do I detect if my mouse if hovering over a specific sprite?
For example I'm making a custom button and I want to check if my mouse is hovering over it so I can make animations.
You need two things:
Texture2d has a very handy propery that does just that)The second point depends of your implementation but you could have a Sprite class that holds a reference to a Texture2d and a Vector2 for the position.
The Bounds property of Texture2 returns a Rectangle which has a Contains method that does exactly what we need. So from here we can write a very simple function that returns true when a point is located within a given sprite.
bool IsPointOverSprite(float x, float y, Sprite sprite)
{
return (sprite.getTexture().getBounds().Contains(pos.X, pos.Y);
}