This project has moved. For the latest updates, please go here.

Odd DebugView/Vertices behavior

Topics: User Forum
Dec 17, 2012 at 9:35 PM

I have some very simple bodies with simple vertices. But when looking at the shape in DebugView, it is pretty off compared to the texture, why?

Look at this image:

They are created like this:

List groundVertices = new List();

List vs = new List();
vs.Add(new Vector2(0, 0));
vs.Add(new Vector2(scaledGSize, 0));
vs.Add(new Vector2(scaledGSize, scaledGSize));
vs.Add(new Vector2(0, scaledGSize));

groundVertices.Add(new Vertices(vs));

Texture2D texture = ScreenManager.Content.Load("Units/Soil");

body = BodyFactory.CreateCompoundPolygon(world, groundVertices, 0f, BodyType.Static);

sprite = new Sprite(texture, AssetCreator.CalculateOrigin(body) / Consts.Scale);

Dec 21, 2012 at 8:20 AM


Dec 22, 2012 at 2:24 AM

The texture to vertices algorithm can have several reasons to find vertices that are not in alignment with the texture. One is the threshold used to distinguish between what is a pixel, and what is not a pixel. Basically it comes down to the quality of the texture. I would recommend that you only use the texture to vertices algorithm when necessary, and it seems that is not in your case.

For the boxes, use BodyFactory.CreateRectangle() and try to simplify your character to something like a rectangle too. This not only speed up the game from the better performance, but also calls for a much more stable simulation.

Dec 22, 2012 at 7:28 AM

That makes sense.. i tried using CreateRectangle instead of CreateCompoundPolygon on the boxes.. it is the same result..

I use TextureToVertices on the body, that i can chance.. but the boxes still look the same.


Body body = BodyFactory.CreateRectangle(World, scaledGSize, scaledGSize, 0f, new Vector2(positionX, positionY));

groundDirtSprite = new Sprite(ScreenManager.Content.Load<Texture2D>("Units/Soil3"), AssetCreator.CalculateOrigin(body) / Consts.Scale);

unit = new DirtGroundUnit(body, groundDirtSprite, density);