Line 34 looks like this: this.body.entity = this;
btw I'm using your plugin - impact-box2d-sugar (
https://github.com/Joncom/impact-box2d-sugar) :)
I think i've understood what the problem was. i made it again like here:
http://www.binarytides.com/make-rope-box2d-javascript/
ig.module(
'game.entities.rope'
)
.requires(
'impact.entity',
'plugins.box2d.entity'
)
.defines(function(){
EntityRope= ig.Box2DEntity.extend({
gravityFactor :1,
_wmDrawBox: true,
_wmBoxColor: 'rgba(150, 150, 255, 0.7)',
createBody: function(x,y,settings) {
//ceiling
var bodyDef = new Box2D.Dynamics.b2BodyDef();
var shapeDef = new Box2D.Collision.Shapes.b2PolygonShape();
shapeDef.SetAsBox(0.5,0.5);
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
fixtureDef.shape = shapeDef;
bodyDef.position.Set(
(this.pos.x +5 ) * Box2D.SCALE,
(this.pos.y +5 ) * Box2D.SCALE
);
this.bodyCeiling = ig.world.CreateBody(bodyDef);
this.bodyCeiling.CreateFixture(fixtureDef);
var prevBody = this.bodyCeiling;
//rope
var rope_height = 0.8;
var rope_width = 0.3;
var last_anchor_point = new Box2D.Common.Math.b2Vec2(0, 0.5);
// start creating rope
for (i=0; i<7;i++){
var bodyRopeDef = new Box2D.Dynamics.b2BodyDef();
bodyRopeDef.position.Set(
(this.pos.x +5 ) * Box2D.SCALE,
(this.pos.y+5 +i*8 ) * Box2D.SCALE
);
bodyRopeDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody,
this.body = ig.world.CreateBody(bodyRopeDef);
var shape2Def = new Box2D.Collision.Shapes.b2PolygonShape();
shape2Def.SetAsBox(rope_width,rope_height);
var fixtureRopeDef = new Box2D.Dynamics.b2FixtureDef();
fixtureRopeDef.shape = shape2Def;
fixtureRopeDef.density = 1;
fixtureRopeDef.friction = 1;
fixtureRopeDef.restitution = 0.5 ;
this.body.CreateFixture(fixtureRopeDef);
var jointDef = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
// jointDef.Initialize(prevBody,this.body,prevBody.GetWorldCenter() ) ;
// jointDef.Initialize(prevBody,this.body, new //Box2D.Common.Math.b2Vec2(this.pos.x*Box2D.SCALE,this.pos.y*Box2D.SCALE+rope_height*i*2)) ;
jointDef.bodyA = prevBody;
jointDef.bodyB = this.body;
jointDef.localAnchorA = last_anchor_point;
jointDef.localAnchorB = new Box2D.Common.Math.b2Vec2(0, rope_height ) ;
this.revJoint = ig.world.CreateJoint(jointDef);
// this.revJoint.collideConnected = false;
last_anchor_point = new Box2D.Common.Math.b2Vec2(0, -1*rope_height ) ;
prevBody = this.body;
}
} ,
})
});
And it works but i still have some problems:
1) this rope consists of 7 sections but the gravity affects only the last one. How can i make gravity work with each section? I think it's not a problem in the standard box2d but in the impact-box2d-sugar it is.
2)I can't understand how does it work :
bodyRopeDef.position.Set(
(this.pos.x +5 ) * Box2D.SCALE,
(this.pos.y+5 +i*8 ) * Box2D.SCALE
);
I mean i'm trying to make each following section appear one by one ( 5 is height and width of my ceiling and 8 is the height of one section) but the last section looks like appear on the top of the my ceiling.. and when rope is initiated it literally falls down from my ceiling body.. If i make position look like this my rope appears from the bottom but it looks stable :
bodyRopeDef.position.Set(
(this.pos.x +5 ) * Box2D.SCALE,
(this.pos.y+300 ) * Box2D.SCALE
);
But of course it's not the right way to do it)
I'll be really appreciate any help!