Box2d custom polygons.

Hi,

For my thesis I’m making a platform game with cocos2d HTML 5 and box2d.
As the floor I would like to use polygon objects.
But I can’t seem to create a polygon.

I’ve tries several ways and none have worked.

This is what I have now:

 var bodyDef = new b2BodyDef();
 bodyDef.type = "static";

 var fixDef = new b2FixtureDef();
 var polyShape = new b2PolygonShape();
 polyShape.vertexCount = 3;
 polyShape.m_vertices[0] = new b2vec2(334.0000, 205.0000);
 polyShape.m_vertices[1] = new b2vec2(310.0000, 203.0000);
 polyShape.m_vertices[2] = new b2vec2(353.0000, 192.0000);

 cc.log(polyShape)

in the console log I see that the m_radius is 0.005 which is obviously wrong.

These are the different ways I’ve tried:

 polyShape.vertices[0].Set(new b2vec2(0,1));
 polyShape.vertices[0].Set(0,1);
 polyShape.m_vertices[0] = [353.0000, 192.0000];
 polyShape.m_vertices[0] = new b2vec2(353.0000, 192.0000);

Any help or tips are greatly appreciated.

Please post the entire procedure you are using to create the polygon. It seems this is just a section, since I don’t see any fixture def, or actually adding it the world.

here’s the whole function:

var bodyDef = new b2BodyDef();
 bodyDef.type = "static";

 var fixDef = new b2FixtureDef();
 var polyShape = new b2PolygonShape();
 polyShape.vertexCount = 3;
 polyShape.m_vertices[0] = new b2vec2(334.0000, 205.0000);
 polyShape.m_vertices[1] = new b2vec2(310.0000, 203.0000);
 polyShape.m_vertices[2] = new b2vec2(353.0000, 192.0000);

 cc.log(polyShape)
 fixDef.shape = polyShape;

 fixDef.density =  1;
 fixDef.friction = 0.5;
 fixDef.restitution = 0.1;

 var body = world.CreateBody(bodyDef);
 body.CreateFixture(fixDef);