This project has moved and is read-only. For the latest updates, please go here.

Creating fixtures for stage geometry

Topics: User Forum
Apr 24, 2011 at 4:34 AM

I had a question about the correct way to handle the static elements of the stages in my game.  I'm creating a side-scrolling platformer in the style of Metroid.  I have a background image, and a set of vertices associated with that image that defines the areas the player cannot enter.  I'm not sure what the optimal way to use these vertices are.  In my placeholder image (ripped straight from Super Metroid) I have a floor and ceiling with several juts out of each, and a door on each side which will need to be opened and closed.

Taking all the floor vertices would define a strange concave polygon, but I'm thinking I only need a series of edges since the player will only interact with stage walls from one side.  Is this the best way to handle this situation?  Will creating a large number (estimating between 10 and 100 depending on the map complexity) of static edge fixtures be the correct solution for an "enclosed space" platformer?

Thanks in advance!

Apr 24, 2011 at 9:46 AM

I'm dealing with a similar scenario right now.  I take the vertices associated with each static element, run them through BayazitDecomposer to partition it into small convex chunks, and finally CreateCompoundPolygon on the result.

Apr 25, 2011 at 1:44 AM

Just fyi, the edge method seems to be working (along with using CreateCompoundPolygon, thanks bicubic ^^), though I need a lot more work with my character to completely test it.  The following is my really really basic code.  It's sloppy but will eventually be optimized and generalized when I get to it.


            Vector2 point1 = new Vector2(0, 238) * METERSPERPIXEL;
            Vector2 point2 = new Vector2(255, 238) * METERSPERPIXEL;
            Vector2 point3 = new Vector2(255, 766) * METERSPERPIXEL;
            Vector2 point4 = new Vector2(904, 766) * METERSPERPIXEL;
            Vector2 point5 = new Vector2(904, 702) * METERSPERPIXEL;

            Vertices edge1 = PolygonTools.CreateLine(point1, point2);
            Vertices edge2 = PolygonTools.CreateLine(point2, point3);
            Vertices edge3 = PolygonTools.CreateLine(point3, point4);
            Vertices edge4 = PolygonTools.CreateLine(point4, point5);

            List<Vertices> vertices = new List<Vertices>(4);

            stageBody = BodyFactory.CreateCompoundPolygon(GameMain.physicsWorld, vertices, 1f);
            stageBody.IsStatic = true;