我正在尝试将精灵纹理添加到 cocos2d 中的 box2d 夹具。目前我有一个动态的身体(用精灵纹理),我试图添加纹理的夹具被添加到身体。
这是我的代码:
b2PolygonShape fixtureShape;
fixtureShape.SetAsBox(0.6f,0.9f,b2Vec2(-1 + 0.1, 1), 45);
b2FixtureDef fixtureDef;
fixtureDef.shape = &fixtureShape;
fixtureDef.density = 0.1f;
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
b2Body *body = world->CreateBody(&bodyDef);
b2CircleShape dynamicBox;
b2FixtureDef mainFixtureDef;
mainFixtureDef.shape = &dynamicBox;
mainFixtureDef.density = 0.1f;
body->CreateFixture(&mainFixtureDef);
body->CreateFixture(&fixtureDef);
CCPhysicsSprite *sprite = [CCPhysicsSprite spriteWithSpriteFrameName:@"sprite1.png"];
[parent addChild:sprite];
[sprite setPTMRatio:PTM_RATIO];
[sprite setB2Body:body];
[sprite setPosition: ccp( p.x, p.y)];
我还没有找到任何关于将精灵添加到固定装置的文档,有人知道这是否可能吗?