Game Development Reference
In-Depth Information
If the point is more right than the leftmost edge of the rectangle, more left
than the rightmost edge, and lower than the top and higher than the bottom,
then the point is in the rectangle. It can be shown visually just like the circle
example.
class RectangleIntersectionState : IGameObject
{
Input _input;
Rectangle _rectangle = new Rectangle(new Vector(0,0,0), new Vector
(200, 200,0));
public RectangleIntersectionState(Input input)
{
_input = input;
}
#region IGameObject Members
public void Update(double elapsedTime)
{
if (_rectangle.Intersects(_input.MousePosition))
{
_rectangle.Color = new Color(1, 0, 0, 1);
}
else
{
// If the circle's not intersected turn it back to white.
_rectangle.Color = new Color(1, 1, 1, 1);
}
}
public void Render()
{
_rectangle.Render();
}
#endregion
}
Here is the state; it's very similar to the circle example before. Remember to make
it load as the default state. The rectangle itself is made using a line loop like the
circle.
Search WWH ::




Custom Search