Cocos2d Box2d缩放半径圆体

时间:2012-10-29 17:29:39

标签: cocos2d-iphone geometry box2d-iphone

目前,在cocos2d中,我有一个应用程序执行以下操作:

使用空白屏幕启动。 当我点击屏幕时,我会弹出一个圆圈。当我按住圆圈时,圆圈将继续以恒定的速度增长。然而,尽管精灵正在增长,但box2d物理体却没有,这意味着精灵不会与其他身体发生碰撞。我一直试图找出一种方法来改变与精灵一起缩放的半径,但这里没有针对cocos2d的问题。我注意到除了cocos2d之外的其他东西的其他box2d但是我很难将它们翻译过来。

//smile.position = ccp(touchLocation.x, touchLocation.y);
smile.scale = .05;
[self addChild:smile];


// b2BodyDef smileBodyDef;

smileBodyDef.type = b2_dynamicBody;
smileBodyDef.position.Set(touchLocation.x/PTM_RATIO, touchLocation.y/PTM_RATIO);
smileBodyDef.userData = smile;
smileBody = world->CreateBody(&smileBodyDef);
//Radius
b2CircleShape smileCircleShape;
int radius = 80;

//Fixture
smileFixtureDef.shape = &smileCircleShape;
smileFixtureDef.density = 0.00f;
smileFixtureDef.friction = .2f;
smileBody->CreateFixture(&smileFixtureDef);




if (CGRectContainsPoint(smileRect, touchLocation)) {
growForever = [CCRepeatForever actionWithAction: [CCScaleBy actionWithDuration: .5 scale:    1.2]];
[growForever setTag:1];
[smile runAction:growForever];

1 个答案:

答案 0 :(得分:2)

每次想要改变半径时,抓住与为身体创建的b2Fixture相关联的形状对象,然后相应地设置新值:

fixture->GetShape()->m_radius = new_radius/PTM_RATIO;