CollideAgainstMove
Introduction
CollideAgainstMove partitioning example
// Use this number to create control how many rectangles are created.
// Let's make a lot of them!
const int numberOfRectangles = 5000;
for (int i = 0; i < numberOfRectangles; i++)
{
// Let's spread out the rectangles
const float minBoundary = -3000;
const float range = 6000;
AxisAlignedRectangle newRectangle = new AxisAlignedRectangle();
newRectangle.Visible = true;
newRectangle.X = minBoundary +
(float)FlatRedBallServices.Random.NextDouble() * range;
newRectangle.Y = minBoundary +
(float)FlatRedBallServices.Random.NextDouble() * range;
newRectangle.Width = 32;
newRectangle.Height = 32;
ShapeCollectionInstance.AxisAlignedRectangles.Add(newRectangle);
}
// Now that all shapes have been added, we need to have the ShapeCollection
// Check the radii of all of its contained shapes. If your ShapeCollection is
// static (that is, no shapes are being added to it), then you only have to do this
// once after all shapes have been added. Otherwise, you will have to do it every
// time you add a shape:
ShapeCollectionInstance.CalculateAllMaxRadii();
// We also need to make sure that we sort all contained objects. If nothing is
// moving or being added to your ShapeCollection, then you only need to call this
// one time as well:
ShapeCollectionInstance.SortAscending(FlatRedBall.Math.Axis.X);Performance benefits
Last updated
Was this helpful?