ok that made a lot of sense in figuring that out, however, since that is the route I'd like to go that means I won't need to use a joint of any kind and can place the spikes in little cavities.
Except. I tried creating the cavities similar to the way I created the spikes by making a class specifically for boundary drawing. When I run the game though I am getting an Assertion Failed Error and I don't know why. Here is a copy of the new class and what the error looks like.
Code:
public var my_body : b2BodyDef = new b2BodyDef();
public static var botP : int = 144 / PhysiVals.worldScale;
public static var topP : int = 0 / PhysiVals.worldScale;
public static var L0 : int = 0 / PhysiVals.worldScale;
public static var L1 : int = 71 / PhysiVals.worldScale;
public static var L2 : int = 77 / PhysiVals.worldScale;
public static var L3 : int = 147 / PhysiVals.worldScale;
public static var L4 : int = 153 / PhysiVals.worldScale;
public static var L5 : int = 223 / PhysiVals.worldScale;
public static var L6 : int = 229 / PhysiVals.worldScale;
public static var L7 : int = 299 / PhysiVals.worldScale;
public static var L8 : int = 305 / PhysiVals.worldScale;
public static var L9 : int = 375 / PhysiVals.worldScale;
public static var L10 : int = 381 / PhysiVals.worldScale;
//top vectors
public static var tv0 : b2Vec2 = new b2Vec2(L0, topP);
public static var tv1 : b2Vec2 = new b2Vec2(L1, topP);
public static var tv2 : b2Vec2 = new b2Vec2(L2, topP);
public static var tv3 : b2Vec2 = new b2Vec2(L3, topP);
public static var tv4 : b2Vec2 = new b2Vec2(L4, topP);
public static var tv5 : b2Vec2 = new b2Vec2(L5, topP);
public static var tv6 : b2Vec2 = new b2Vec2(L6, topP);
public static var tv7 : b2Vec2 = new b2Vec2(L7, topP);
public static var tv8 : b2Vec2 = new b2Vec2(L8, topP);
public static var tv9 : b2Vec2 = new b2Vec2(L9, topP);
public static var tv10 : b2Vec2 = new b2Vec2(L10, topP);
//bottom vectors
public static var bv0 : b2Vec2 = new b2Vec2(L0, botP);
public static var bv1 : b2Vec2 = new b2Vec2(L1, botP);
public static var bv2 : b2Vec2 = new b2Vec2(L2, botP);
public static var bv3 : b2Vec2 = new b2Vec2(L3, botP);
public static var bv4 : b2Vec2 = new b2Vec2(L4, botP);
public static var bv5 : b2Vec2 = new b2Vec2(L5, botP);
public static var bv6 : b2Vec2 = new b2Vec2(L6, botP);
public static var bv7 : b2Vec2 = new b2Vec2(L7, botP);
public static var bv8 : b2Vec2 = new b2Vec2(L8, botP);
public static var bv9 : b2Vec2 = new b2Vec2(L9, botP);
public static var bv10 : b2Vec2 = new b2Vec2(L10, botP);
public function Bounds()
{
DrawBounds(214,300,40,600,"leftWall");
DrawBounds(635, 300, 40, 600, "rightWall");
DrawGround();
}
//static public function get world():b2World { return _world; }
public function DrawBounds(px,py,w,h,ud):void
{
//my_body = new b2BodyDef();
my_body.position.Set(px/PhysiVals.worldScale, py/PhysiVals.worldScale);
var my_box:b2PolygonShape = new b2PolygonShape();
my_box.SetAsBox(w/2/PhysiVals.worldScale, h/2/PhysiVals.worldScale);
var my_fixture:b2FixtureDef = new b2FixtureDef();
my_fixture.shape=my_box;
my_fixture.density = 0;
my_fixture.restitution = .3;
my_fixture.friction = .6;
var world_body:b2Body=PhysiVals.world.CreateBody(my_body);
world_body.SetUserData(ud);
world_body.CreateFixture(my_fixture);
}
public function DrawGround():void
{
my_body.position.Set(425 / PhysiVals.worldScale, 602 / PhysiVals.worldScale);
var leftSide:b2PolygonShape = new b2PolygonShape();
leftSide.SetAsEdge(tv0, bv0);
var leftFixt:b2FixtureDef = new b2FixtureDef();
leftFixt.shape = leftSide;
var top:b2PolygonShape = new b2PolygonShape();
top.SetAsEdge(tv0, tv10);
var topFixt:b2FixtureDef = new b2FixtureDef();
topFixt.shape = top;
topFixt.filter.groupIndex = -1;
topFixt.restitution = 0.1;
var spacer1:b2PolygonShape = new b2PolygonShape();
spacer1.SetAsArray([tv2, bv2, bv1, tv1], 4);
var sFixt1:b2FixtureDef = new b2FixtureDef();
sFixt1.shape = spacer1;
var spacer2:b2PolygonShape = new b2PolygonShape();
spacer2.SetAsArray([tv4, bv4, bv3, tv3], 4);
var sFixt2:b2FixtureDef = new b2FixtureDef();
sFixt2.shape = spacer2;
var spacer3:b2PolygonShape = new b2PolygonShape();
spacer3.SetAsArray([tv6, bv6, bv5, tv5], 4);
var sFixt3:b2FixtureDef = new b2FixtureDef();
sFixt3.shape = spacer3;
var spacer4:b2PolygonShape = new b2PolygonShape();
spacer4.SetAsArray([tv8, bv7, bv7, tv7], 4);
var sFixt4:b2FixtureDef = new b2FixtureDef();
sFixt4.shape = spacer4;
var spacer5:b2PolygonShape = new b2PolygonShape();
spacer5.SetAsArray([tv10, bv10, bv9, tv9], 4);
var sFixt5:b2FixtureDef = new b2FixtureDef();
sFixt5.shape = spacer5;
var bot:b2PolygonShape = new b2PolygonShape();
bot.SetAsEdge(bv0, bv10);
var botFixt:b2FixtureDef = new b2FixtureDef();
botFixt.shape = bot;
var rightSide:b2PolygonShape = new b2PolygonShape();
rightSide.SetAsEdge(tv10, bv10);
var rightFixt:b2FixtureDef = new b2FixtureDef();
rightFixt.shape = rightSide;
var world_body:b2Body=PhysiVals.world.CreateBody(my_body);
world_body.SetUserData("ground");
world_body.CreateFixture(leftFixt);
world_body.CreateFixture(topFixt);
world_body.CreateFixture(sFixt1);
world_body.CreateFixture(sFixt2);
world_body.CreateFixture(sFixt3);
world_body.CreateFixture(sFixt4);
world_body.CreateFixture(sFixt5);
world_body.CreateFixture(botFixt);
world_body.CreateFixture(rightFixt);
}
Code:
Assertion Failed
at Box2D.Common::b2Settings$/b2Assert()
at Box2D.Collision.Shapes::b2PolygonShape/SetAsVector()
at Box2D.Collision.Shapes::b2PolygonShape/SetAsArray()
at Bounds/DrawGround()
at Bounds()
at Arbles/CreateLevel()
at Arbles()
at DocumentClass/startGame()
at DocumentClass/onRequestStart()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at StartScreen/onClickStart()
Now the body itself is not convex but each shape is, would that cause a problem, and would I be better off in making each one of the shapes a separate body instead? I'm very confused as I have never seen this error befor.