Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a code, that add a vertex array to a shape, my code is:

PolygonDef shape = new PolygonDef(); 
for (int i=0; i<vertices.size(); i++) {
    Vec2 v = vertices.get(i);
    shape.addVertex(new Vec2(v.x/RATIO,v.y/RATIO));

But its very strange because not working good on any of my polygon creator tool.

So with a triangle, it work good:

    ArrayList<Vec2> vertices = new ArrayList<Vec2>();

    vertices.add(new Vec2(0,-size.height/2));
    vertices.add(new Vec2(size.width/2,size.height/2));
    vertices.add(new Vec2(-size.width/2,size.height/2));

but with a bigger polygon of 50 to 60 vertices it's not working.

How I can create a usable vertex array from a shape? I have a greyscaled image with black and white colors... How can use this shape (image) to define my vertex array good?

And in box2D with the addVertex how I can add this points to make a normal usable polygon? (counter clockwise?)

share|improve this question

(J)Box2D polygons are limited to 8 vertices. When you say it's "not working" I assume you mean you're getting the assert that fires when you pass in arrays that are too large, which should've led you to this yourself.

You will need to triangulate your polygons.

share|improve this answer
yeah I know that 8 vertices, but I recompiled the original Jbox2D source codes, with the number 64. "public static final int maxPolygonVertices = 64;" and made a new .jar file from it. How can I triangulate my polygons? – lacas May 4 '11 at 9:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.