AxisAlignedRectangle
Introduction
The AxisAlignedRectangle is a PositionedObject which is used for unrotated bounding box collision. This is preferred over Polygon collision if Sprites are not rotated due to speed and memory usage considerations. AxisAlignedRectangles share many similarities with the other shape classes (Circle, Line, and Polygon). For general information about shapes, see the ShapeManager wiki entry. For information on using AxisAlignedRectangles in Glue, see this page. AxisAlignedRectangles do not support being filled-in. They can only render as an outline. To render a solid rectangle, look at using Sprites with the Color ColorOperation
What does "axis aligned" mean?
AxisAlignedRectangles are PositionedObjects
The AxisAlignedRectangle class inherits from PositionedObject. This means that all properties which are available to PositionedObjects (excluding rotation) are available to AxisAlignedRectangles. For more information, see the PositionedObject page.
Creating an AxisAlignedRectangle
AxisAlignedRectangles are created through the ShapeManager. The following code creates an AxisAlignedRectangle through the ShapeManager and resizes it: Add the following using statement
Create the instance:
Relationship with ShapeManager
Move (Solid) Collision
Solid or moving collision can be performed with AxisAlignedRectangles as well as Polygons and Circles. The following code creates three AxisAlignedRectangles - one controlled by the player, one which can be pushed, and one which is is immovable. Add the following using statements:
Add the following at class scope:
Add the following in Initialize after Initializing FlatRedBall:
Add the following in Update:
Determining Collision Side
For information on determining which side an object has collided on, see this page on LastMoveCollisionReposition.
AxisAlignedRectangle Members
Extra Information
Did this article leave any questions unanswered? Post any question in our forums for a rapid response.
Last updated