gpt4 book ai didi

cocos2d-iphone - Cocos2d Box2d 多b2circle shape fixture for one body with positioning

转载 作者:行者123 更新时间:2023-12-03 22:42:44 25 4
gpt4 key购买 nike

有人知道如何将 2 个圆形夹具添加到一个具有所需定位的 b2body 吗?我知道如何使用 m_centroid 将两个多边形夹具添加到一个物体上。但是对于圆形灯具我该怎么做。

任何答案将不胜感激。我想把一些物体粘在一起。我试过关节,但它们都是有弹性的。我想要静态距离。

谢谢大家!

最佳答案

你应该为你的 body 创建两个固定装置,这些固定装置的形状应该是 b2CircleShape

//Create a body. You'll need a b2BodyDef, but I've assumed you know how to use these since you say you've created bodies successfully before.
b2Body* body = world->CreateBody(&bodyDef);

//Create the first circle shape. It's offset from the center of the body by -2, 0.
b2CircleShape circleShape1;
circleShape1.m_radius = 0.5f;
circleShape1.m_p.Set(-2.0f, 0.0f);

b2FixtureDef circle1FixtureDef;
circle1FixtureDef.shape = &circleShape1;
circle1FixtureDef.density = 1.0f;


//Create the second circle shape. It's offset from the center of the body by 2, 0.
b2CircleShape circleShape2;
circleShape2.m_radius = 0.5f;
circleShape2.m_p.Set(2.0f, 0.0f);

b2FixtureDef circle2FixtureDef;
circle2FixtureDef.shape = &circleShape2;
circle2FixtureDef.density = 1.0f;


//Attach both of these fixtures to the body.
body->CreateFixture(&circle1FixtureDef);
body->CreateFixture(&circle2FixtureDef);

关于cocos2d-iphone - Cocos2d Box2d 多b2circle shape fixture for one body with positioning,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8007170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com