How to create realistic ropes using cocos2d-x and box2d?

Good day to all!

I have been coding cocos2d-x for some time now and I am starting to integrate box2D
in my game, I am really new in box2D and I have manage to play around with the example with cat and
car for collisions. What I want to achieve now is to have a realistic rope with an object attached
in the end.

I have been trying to port this tutorial ( http://www.cocos2d-iphone.org/archives/1112 ) to android for the whole day and I still
haven’t figure out how to do this. I already have the VRope-x class for Velvet rope
in android https://github.com/teemukorh/VRope-x but it still doesn’t work.

I tried porting the whole tutorial to android and it has no errors when I compiled it but when I try to run it
and press on the play menu to proceed to the game scene it actually stops. No message nor error, it just stops. :frowning:

Can someone please guide me? Any help is greatly appreciated! :slight_smile:

There is the “RopeJoint” test in the Samples/TestCPP project, have you tried that?

This is the port of first part from raywenderlich cut the rope tutorial…
2nd part is not proper but you will get upto rope drawing using verlet rope…

Thanks for your reply, I was able to run the Velvet rope and I am trying to
use CCSprite for the rope and player but I can’t seem to figure out how :; //center body on screen
anchorBody = world
>CreateBody(&anchorBodyDef);

CCSpriteBatchNode parent = CCSpriteBatchNode::batchNodeWithFile;
m_pSpriteTexture = parent~~>getTexture;
addChild;
Box2DSprite* sp = addNewSpriteAtPosition);
CCSpriteBatchNode* ropeBatch = CCSpriteBatchNode::batchNodeWithFile;
addChild;
VRope* verlet = createRope;
sp~~>mRope = verlet;
</pre>
and the adddNewSpritePosition function is:
<pre>
Box2DSprite
GameScene::addNewSpriteAtPosition(CCPoint p)
{
CCSize size = CCDirector::sharedDirector()>getWinSize;
CCLOG (“Add sprite %0.2f x %02.f”,p.x,p.y);
CCNode* parent = getChildByTag;
//We have a 64x64 sprite sheet with 4 different 32x32 images. The following code is
//just randomly picking one of the images
Box2DSprite **sprite = new Box2DSprite;
sprite
>initWithTexture;
sprite~~>setScaleX.width) / 2 ) / 2) / 1.3)) );
sprite~~>setScaleY.height) / 2 ) / 2) / 1.3)) );
sprite~~>autorelease;
parent~~>addChild;
sprite~~>setPosition );
sprite~~>createPhysicsBody;
return sprite;
}
</pre>
and this is the create physicsBody for the sprite:
<pre>
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set;
mBody = mWorld~~>CreateBody;
// Define another box shape for our dynamic body.
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox.width** getScaleX) / PTM_RATIO, .height * getScaleY) / PTM_RATIO);//These are mid points for our 1m box
//dynamicBox.SetAsBox;
// Define the dynamic body fixture.
b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox;
fixtureDef.density = 0.5f;
fixtureDef.friction = 0.3f;
mBody~~>CreateFixture(&fixtureDef);

mBody~~>SetUserData;
</pre>
When I tried using CCSprite it doesn’t work,
<pre>
*pSprite = CCSprite::create;
*pSprite~~>setScaleX( ((((( size.width / *pSprite~~>getContentSize.width) / 2 ) / 2) / 1.3)) );
_pSprite~~>setScaleY.height) / 2 ) / 2) / 1.3)) );
*pSprite~~>setPosition );
this~~>addChild(_pSprite, 2);

b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(location.x/PTM_RATIO, location.y/PTM_RATIO);

mBody = mWorld~~>CreateBody;
// Define another box shape for our dynamic body.
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox.width * getScaleX) / PTM_RATIO, .height * getScaleY) / PTM_RATIO);//These are mid points for our 1m box
//dynamicBox.SetAsBox;
// Define the dynamic body fixture.
b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox;
fixtureDef.density = 0.5f;
fixtureDef.friction = 0.3f;
mBody~~>CreateFixture(&fixtureDef);

mBody->SetUserData(_pSprite);

Can someone point to me what am I doing wrong? Is there something wrong the way I create fixtures and body?

Thanks!