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

3.0 -- texture to loopshape -- multiple polygons?

Topics: Developer Forum
Sep 27, 2010 at 3:03 AM

Hi all.

I'm using TextureConvert.CreateVertices to get vertices out of my texture.  I then manipulate that list of vertices (flip the Y value, scale the vertices properly), and create a LoopShape.  Then create a body, and add the loopshape as a fixture, and bam, I have a great physical landscape.

The problem comes in when I want to have multiple physical objects (that is, multiple loop shapes) defined in the same texture file.  The CreateVertices method apparently just looks at the first block of non-transparent pixels it finds, makes a polygon, and then quits.  I'd like it to make polygons for all polygons in my texture.  Anyone done anything like this?

At worst case, I can create a texture for each individual polygon, but it would be nice to define them all in the same image.



Sep 27, 2010 at 3:07 AM

Here's an image of what I'm talking about

I want to add an "island" in mid-air.  I can create a new texture, but it would be nice to have multiple polygons in the same file.


Sep 27, 2010 at 1:07 PM

The method:


has an overload you can set to true. It enables the multipart detection.

Sep 27, 2010 at 5:30 PM

Aweome.  I'm looking at it right now. 

I think there is a minor bug, in that the multiPartDetection and holeDetection bool parameters get reversed in the call to CreateVertices below...


        public static List<Vertices> CreatePolygon(uint[] data, int width, int height, float hullTolerance,
                                                   byte alphaTolerance, bool multiPartDetection, bool holeDetection)
            return TextureConverter.CreateVertices(data, width, height, hullTolerance, alphaTolerance, holeDetection,

Reversing the parameters returns a list of lists of vertices, so I think it's working!  I'll have to investigate further when I get home.  Thanks!

Sep 27, 2010 at 5:47 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.