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

Help with multiple polygons

Topics: Developer Forum
Apr 10, 2012 at 2:39 AM

Hi folks.


Here is what I am trying to do:

I want to have 10 or so stationary polygons in the level with which the ball collides and reacts to physics.


Here is what I have so far:

1) Vertex coordinates for each of the polygons

2) Code to read in these coordinates from text file and do a PixelToMeters conversion on them

3) Code to use the EarClipping decomposition to break each of these polygons

4) I add each of the broken polygons (25 or so for each of the 10 polygons) as a static Body

List<Vertices> polygons = EarclipDecomposer.ConvexPartition(tempVertices);
                                foreach (Vertices polygon in polygons)
                                    Body polygonBody = BodyFactory.CreatePolygon(world, polygon, 1f);
                                    polygonBody.BodyType = BodyType.Static;
                                    polygonBody.Restitution = 0.3f;
                                    polygonBody.Friction = 0.5f;


Here is what I am confused on:

1) They're not being grouped up right for some reason because the ball is reacting oddly. How does the "origin" thing work for CreatePolygon method?

2) How the heck do I SEE where the polygons are?

Apr 11, 2012 at 6:55 PM

Isn't it better to create a compound polygon or you really need them to be separate bodies (that's like 25x10=250 bodies)? 

1) What's "the origin thing". Once the polygon is attached to a body as a fixture's shape you can set Body.Position to move the body and it's fixtures. I don't see you setting positions anywhere so all bodies are created at (0,0) on top of each other?

2) Draw the body's fixture's shape - that's your polygon.