Box2D Forums

It is currently Tue May 21, 2013 5:38 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Thu Jan 19, 2012 7:19 am 
Offline

Joined: Fri Feb 05, 2010 4:41 am
Posts: 4
Hi guys.

I'm new to box2d and wck, but I found it very good to use.
I'm working on a project where I add bubbles to the world, what works perfectly, but when I want to add joints to each bubble than I can't figure out how to do that.
This code doesn't work as I expected:
Code:
var joint:Joint = new BubbleJoint();
joint.connectorClassName = "Connectline";
joint.type = "Distance";
joint.target1Object = newBubble; // newly created Bubble BodyShape
joint.target2Object = MLM_WORLD.B1; // old Bubble BodyShape
Util.addChildAbove(joint, newBubble);
joint.create();

The result is the bubble is sticked to the position where it has been created.
I tried to give all different parameters to the target1Object and target2Object, but none of them works.
On the other hand this code works perfectly:
Code:
var distanceJointDef:b2DistanceJointDef = new b2DistanceJointDef(); 
distanceJointDef.Initialize(newBubble.b2body, MLM_WORLD.B1.b2body,
   newBubble.b2body.GetWorldCenter(), MLM_WORLD.B1.b2body.GetWorldCenter());
MLM_WORLD.b2world.CreateJoint(distanceJointDef);


Is there a way to make the wck version to work or there is a bug in it?

Thank you.


Top
 Profile  
 
PostPosted: Mon Feb 06, 2012 8:13 pm 
Offline

Joined: Fri Dec 14, 2007 8:07 pm
Posts: 913
I'm not sure exactly what's going on but there's a couple things I see wrong:

Quote:
Util.addChildAbove(joint, newBubble);
joint.create();


You don't need to call joint.create(). This is called automatically when you add it to the stage.

Also try setting the x & y of your joint object to the x & y of your target1Object. Try that and see if it fixes things.


Top
 Profile  
 
PostPosted: Wed Feb 08, 2012 3:32 pm 
Offline

Joined: Fri Feb 05, 2010 4:41 am
Posts: 4
Thank you mayobutter, I'll try that.

Gergely


Top
 Profile  
 
PostPosted: Thu Feb 23, 2012 3:43 am 
Offline

Joined: Fri Feb 05, 2010 4:41 am
Posts: 4
Thanks Mayobutter, it worked fine with your suggestions! ;)
Code:
var j:Joint = new Joint();
j.type = "Distance";
j.bodyShape1 = parent.bubble;
j.bodyShape2 = newBubble;
Util.addChildAtPos(view.MLM_WORLD, j, parent.bubble);


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group