Cocos2d动态改变box2d形状半径

时间:2014-07-30 09:29:02

标签: cocos2d-iphone box2d sprite shape

我可以点击更改box2d半径吗?这是代码

b2BodyDef ballBodyDef;
ballBodyDef.type = b2_dynamicBody;
ballBodyDef.position.Set(pos.x / PTM_RATIO, pos.y / PTM_RATIO);
ballBodyDef.userData = mainBallon;
_bodyMain = _world->CreateBody(&ballBodyDef);

circleMain.m_radius = circleRadius / PTM_RATIO;

ballShapeDefMain.shape = &circleMain;
ballShapeDefMain.density = 1.0f;
ballShapeDefMain.friction = 0.2f;
ballShapeDefMain.restitution = 0.8f;
_bodyMain->CreateFixture(&ballShapeDefMain);

我想在这种方法中增加半径。

-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

我试过了:

circleMain.m_radius = NewRadius;
_bodyMain->ResetMassData();

和此:

b2Fixture *fixtureA = _bodyMain->GetFixtureList();
_bodyMain->DestroyFixture(fixtureA);

b2CircleShape circleShape;
circleShape.m_radius = NewRadius;

b2FixtureDef fixtureDef;
fixtureDef.shape = &circleShape;
fixtureDef.density = 1;
fixtureDef.friction = 0.2f;
fixtureDef.restitution = 0.8f;
_bodyMain->CreateFixture(&fixtureDef);

但两者都不会工作。

0 个答案:

没有答案