How to bind sprite to joint?

How to bind sprite to joint?
0.0 0


In box2d test there is example how to bind sprite to box2d body. And how to do same with joint ? Anybody help !


If I understand correctly, you need to bind sprite to join?
you can use Userdata. sample:

@ b2RevoluteJointDef jointDef;
jointDef.userData = m_sprite;@


Are you sure ? I tried this. Only joint was created, and there is no sprite connected to it :frowning:


Please, if you can show your code.


void HelloWorld::addNewConnect (b2Body * myBodyA, b2Body * myBodyB) {

b2DistanceJointDef jointDef;

jointDef.Initialize(myBodyA, myBodyB, myBodyA~~>GetWorldCenter, myBodyB~~>GetWorldCenter());

CCSprite * temp = CCSprite::create(“CloseSelected.png”);

jointDef.userData = temp;
b2DistanceJoint* joint = (b2DistanceJoint*)world->CreateJoint(&jointDef);


I can not understand why it is you need.
You can see how bind sprite to box2d body.

b2DistanceJoint* joint = (b2DistanceJoint*)world->CreateJoint(&jointDef); for (b2Joint* f = joint; f; f = f->GetNext()) { CCSprite* m_sprite = static_cast<CCSprite*>(f->GetUserData()); if(m_sprite) { //you operation with sprite //m_sprite->setVisible(false); } }
Sorry i have bad english


I have two bodies. Between them should be colored line - distance joint. I created bodies using PhysicsSprite class from standart box2dtest. Please, open cocos2d-x tests and find this example. There are boxes, please, tell me, how to create visible joints between them ?


maybe you are talking about debug mode?

see here (i’m used this)


Only with debug draw Box2d;
GLESDebugDraw m_debugDraw;
unsigned int flag;
m_debugDraw_>SetFlag(flag);//Set flag e_joinBit

But this metog set visible all joint in scene.

For semulate joint draw, you can add body in joint point, and add to it the sprite object.

Sorry i have bad english, too.


Vitaly, do you speak russian ? Please, add me in skype : umni4ek, or in icq 591 476 364. Or on, my id 770044


Ok. After 20.00PM by Moskow time.