How to make Edge Chain in Box2d v2.1 ? There is b2EdgeChainDef class (help: This structure is used to build edge shapes). But I have no idea how to get some edge chain from it. May be some have good chunk of code for this ? Sharing this would be helpful.
How to make Edge Chain
FlashI might be wrong on this, but I think edge chains are broken at the moment?
In any case, you can just use a polygon with 2 points, like this:
In both cases, ground is a b2Body you've made, so remember to set:
Both ways return the actual fixture incase you want to keep a list of them.
Hope that helps 🙂
In any case, you can just use a polygon with 2 points, like this:
Code:
//Simple way with no fixture.
var polyShape:b2PolygonShape = new b2PolygonShape();
var startPoint:b2Vec2 = new b2Vec2(0, 0 );
var endPoint:b2Vec2 = new b2Vec2(20, 20 );
polyShape.SetAsArray( [startPoint, endPoint], 2 );
ground.CreateFixture2(bob, 1.0);
//Using a fixture for greater control.
var polyShape:b2PolygonShape = new b2PolygonShape();
var startPoint:b2Vec2 = new b2Vec2(0, 0 );
var endPoint:b2Vec2 = new b2Vec2(20, 20 );
polyShape.SetAsArray( [startPoint, endPoint], 2 );
var fixDef:b2FixtureDef = new b2FixtureDef();
fixDef.shape = polyShape;
fixDef.restitution = 0.8;
fixDef.friction = 0.7; //etc
ground.CreateFixture(bob);
var polyShape:b2PolygonShape = new b2PolygonShape();
var startPoint:b2Vec2 = new b2Vec2(0, 0 );
var endPoint:b2Vec2 = new b2Vec2(20, 20 );
polyShape.SetAsArray( [startPoint, endPoint], 2 );
ground.CreateFixture2(bob, 1.0);
//Using a fixture for greater control.
var polyShape:b2PolygonShape = new b2PolygonShape();
var startPoint:b2Vec2 = new b2Vec2(0, 0 );
var endPoint:b2Vec2 = new b2Vec2(20, 20 );
polyShape.SetAsArray( [startPoint, endPoint], 2 );
var fixDef:b2FixtureDef = new b2FixtureDef();
fixDef.shape = polyShape;
fixDef.restitution = 0.8;
fixDef.friction = 0.7; //etc
ground.CreateFixture(bob);
In both cases, ground is a b2Body you've made, so remember to set:
Code:
ground.SetType(b2Body.b2_staticBody);
Both ways return the actual fixture incase you want to keep a list of them.
Hope that helps 🙂
Thank. It works.
Original thread: https://box2d.org/forum/viewtopic.php?t=7757