使用 box2d cocos2d 不会改变体重
我只是不明白这个大东西是如何运作的。 我已经阅读了 box2d 文档(其中有许多目前 cocos2d 中没有的命令),我试图理解大量的事情。
我知道如果我改变身体密度,它不会改变任何事情:
//add body
b2BodyDef spriteBodyDef;
spriteBodyDef.type =b2_dynamicBody; //b2_staticBody;
spriteBodyDef.position.Set(pilot1.position.x/PTM_RATIO,pilot1.position.y/PTM_RATIO);
spriteBodyDef.userData = pilot1;
pilot1Body = world->CreateBody(&spriteBodyDef);
b2CircleShape spriteShape; //b2polygon-for box shape
spriteShape.m_radius = 15.0/PTM_RATIO;
b2FixtureDef spriteShapeDef;
spriteShapeDef.restitution = 0.4f;
spriteShapeDef.shape = &spriteShape;
//spriteShapeDef.density=10.0f;
b2Fixture *fix=pilot1Body->GetFixtureList();
fix->SetDensity(1.5f);
pilot1Body->ResetMassData();
NSLog(@"mass2: %f", pilot1Body->GetMass());
spriteShapeDef.isSensor = false;
pilot1Body->CreateFixture(&spriteShapeDef);
[self addChild:pilot1];
非常感谢。
i just cant figure out how this mass thing works .
i have read the box2d docs, (which have many commands that are not in the cocos2d at the moment) and i was trying to understand the mass thing.
i know that if i change the body density it doesnt change a thing :
//add body
b2BodyDef spriteBodyDef;
spriteBodyDef.type =b2_dynamicBody; //b2_staticBody;
spriteBodyDef.position.Set(pilot1.position.x/PTM_RATIO,pilot1.position.y/PTM_RATIO);
spriteBodyDef.userData = pilot1;
pilot1Body = world->CreateBody(&spriteBodyDef);
b2CircleShape spriteShape; //b2polygon-for box shape
spriteShape.m_radius = 15.0/PTM_RATIO;
b2FixtureDef spriteShapeDef;
spriteShapeDef.restitution = 0.4f;
spriteShapeDef.shape = &spriteShape;
//spriteShapeDef.density=10.0f;
b2Fixture *fix=pilot1Body->GetFixtureList();
fix->SetDensity(1.5f);
pilot1Body->ResetMassData();
NSLog(@"mass2: %f", pilot1Body->GetMass());
spriteShapeDef.isSensor = false;
pilot1Body->CreateFixture(&spriteShapeDef);
[self addChild:pilot1];
thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用
b2Fixture::SetDensity
为附加到主体的部分或全部灯具设置新的密度,然后调用b2Body::ResetMassData
,例如:You need to set new density for some or all the fixtures attached to the body using
b2Fixture::SetDensity
and then callb2Body::ResetMassData
, for example: