ShapeCollection
Introduction
The ShapeCollection class is a container for a variety of shapes. The ShapeCollection class is often used for collision maps and to define triggers. ShapeCollections are often loaded from .shcx files created by the PolygonEditor. ShapeCollections are a very common class due to the support of .shcx files in Glue.
Accessing Shapes
The ShapeCollection provides a number of methods that can be used to perform actions on all contained Shapes (such as AttachTo). However, you may be working on a game that requires access to individual shapes. The ShapeCollection exposes its shapes. The following members are available:
AxisAlignedRectangles
AxisAlignedCubes
Capsule2Ds
Circles
Lines
Polygons
Spheres
These are all PositionedObjectLists which can be accessed like regular lists. You can add and remove elements from these lists as well as modify the individual members inside the lists. If your need to perform special actions on all elements in a ShapeCollection you can do the following:
Of course, you can also access the shapes using a foreach statement. Keep in mind that foreach statements may have performance penalties compared to regular for loops.
Loading a ShapeCollection
ShapeCollections can be created by loading .shcx files.
Loading ShapeCollection From File
The following code loads a .shcx file into memory, adds all contained shapes to the ShapeManager. If you are using Glue you can add ShapeCollections to Screens and Entities just like other files. For an example on how to add a ShapeCollection to Glue, see the Beefball tutorial on creating Screen collisions. File used: ShapeCollection.shcx Add the following using statements:
Add the following to Initialize after initializing FlatRedBall:
Saving a ShapeCollection
Although most games do not need ShapeCollection saving support, FlatRedBall provides easy-to-use classes for saving a ShapeCollection. For more information, see the ShapeCollectionSave page.
ShapeCollection Shapes
All shapes in the ShapeCollection can be accessed through its member lists. The available lists are:
AxisAlignedRectangles
AxisAlignedCubes
Circles
Polygons
Lines
Spheres
The ShapeCollection can be thought of as a container for all of these lists. Therefore, you can use the individual lists to do anything you would do with a normal list such as:
Last updated