The Polygon class is used to draw line polygons (as opposed to solid colored or textured polygons) as well as for 2D collisions. This wiki entry will cover common usage of the Polygon class. The Polygon class sits in the FlatRedBall.Math.Geometry namespace, so adding

can reduce the amount of required code. Also, Polygons use the FlatRedBall.Math.Geometry.Point struct, so the following code will solve ambiguities:

Creating a Rectangle Polygon

The Polygon class provides the CreateRectangle  shortcut methods for creating common Polygons:

You can also assign the Points object. For more information, see the Points page.

Creating a Polygon From Points

Polygon as a PositionedObject

The Polygon class inherits from the FlatRedBall.PositionedObject class. See the FlatRedBall.PositionedObject wiki entry for editing properties.

Polygon Collision

The Polygon class provides collision methods and properties to simplify common game programming tasks. The following code creates two Polygons which turn red when they collide. Note that this uses input code. For information on using FlatRedBall input, see FlatRedBall.Input.InputManager.

Efficiency of Polygon Collision

Each Polygon has a BoundingRadius method which is set when the point list reference is updated. This BoundingRadius is used internally in collision methods. When two Polygons collide, their distances are compared to their BoundingRadius. If the two are too far away to possibly have a collision, then no deeper checks are performed.


This method repositions a Polygon or its TopParent if it has one, changes the LastMoveCollisionReposition property, and finally updates all attachments. This code performs all of the updates which would happen on a successful CollideAgainstMove call.

This method is rarely used. It can be used if collision is handled outside of the polygon class but the LastMoveCollisionReposition property is still used in other parts of code. If collision that repositions a polygon calls this method rather than simply changing its Position values, then code that uses the LastMoveCollisionReposition property (such as ProjectParentVelocityOnLastMoveCollisionTangent) will still work correctly.

Additional Information