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 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.
Can someone please guide me? Any help is greatly appreciated!
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);