I'm following Todd's tutorial about Peggle game and can't find out how to convert this code in ArbiStaticActor.as to Box2DFlash 2.1a:
Basically what this code should do is get an array containing arrays of coordinates to attach multiple polygon shapes to a single body. Any help to convert this to 2.1a would be GREATLY appreciated!!
Code:
private function createBodyFromCoords(arrayOfCoords:Array, location:Point):b2Body {
var allShapeDefs:Array = [];
for each (var listOfPoints:Array in arrayOfCoords) {
var newShapeDef:b2PolygonShape = new b2PolygonShape();
newShapeDef.vertexCount = listOfPoints.length;
for (var i:int = 0; i < listOfPoints.length; i++) {
var nextPoint:Point = listOfPoints[i];
b2Vec2(newShapeDef.vertices[i]).Set(nextPoint.x / PhysiVals.RATIO, nextPoint.y / PhysiVals.RATIO);
}
newShapeDef.density = 0;
newShapeDef.friction = 0.2;
newShapeDef.restitution = 0.3;
allShapeDefs.push(newShapeDef);
}
var arbiBodyDef:b2BodyDef = new b2BodyDef();
arbiBodyDef.position.Set(location.x / PhysiVals.RATIO, location.y / PhysiVals.RATIO);
var arbiBody:b2Body = PhysiVals.world.CreateBody(arbiBodyDef);
for each (var newShapeDef:b2ShapeDef in allShapeDefs) {
arbiBody.CreateShape(newShapeDef);
}
arbiBody.SetMassFromShapes();
return arbiBody;
}
var allShapeDefs:Array = [];
for each (var listOfPoints:Array in arrayOfCoords) {
var newShapeDef:b2PolygonShape = new b2PolygonShape();
newShapeDef.vertexCount = listOfPoints.length;
for (var i:int = 0; i < listOfPoints.length; i++) {
var nextPoint:Point = listOfPoints[i];
b2Vec2(newShapeDef.vertices[i]).Set(nextPoint.x / PhysiVals.RATIO, nextPoint.y / PhysiVals.RATIO);
}
newShapeDef.density = 0;
newShapeDef.friction = 0.2;
newShapeDef.restitution = 0.3;
allShapeDefs.push(newShapeDef);
}
var arbiBodyDef:b2BodyDef = new b2BodyDef();
arbiBodyDef.position.Set(location.x / PhysiVals.RATIO, location.y / PhysiVals.RATIO);
var arbiBody:b2Body = PhysiVals.world.CreateBody(arbiBodyDef);
for each (var newShapeDef:b2ShapeDef in allShapeDefs) {
arbiBody.CreateShape(newShapeDef);
}
arbiBody.SetMassFromShapes();
return arbiBody;
}
Basically what this code should do is get an array containing arrays of coordinates to attach multiple polygon shapes to a single body. Any help to convert this to 2.1a would be GREATLY appreciated!!