[英]Unique Bodies In AndEngine Box2D
I want to create an unique physics body for use on a sprite. 我想创建一个用于精灵的独特物理实体。 This sprite will need to have two portions where there is a colliding surface and an open space.
该子画面需要具有两个部分,其中有一个碰撞表面和一个开放空间。
Example: 例:
In the example provided above, the sprite would need to have a physics box2d body where the two green spaces need physics and the brown middle would need to be "empty" or have no physical attributes. 在上面提供的示例中,子画面需要具有一个物理box2d主体,其中两个绿色空间需要进行物理处理,而棕色中部则需要为“空”或没有物理属性。 Is this possible or do I need to create two sprites?
这可能吗,还是我需要创建两个精灵?
Yes, it is possibly. 是的,可能是这样。 You need to create one body and two fixtures for each green part.
您需要为每个绿色零件创建一个实体和两个灯具。
b2BodyDef myBodyDef;
myBodyDef.type = b2_dynamicBody;
b2Body* dynamicBody = m_world->CreateBody(&myBodyDef);
b2PolygonShape polygonShape;
b2FixtureDef myFixtureDef;
myFixtureDef.shape = &polygonShape;
// Left green rectangle
b2Vec2 vertices[4];
vertices[0].Set(0, 0);
vertices[1].Set(1, 0);
vertices[2].Set(1, 0.5);
vertices[3].Set(0, 0.5);
polygonShape.Set(vertices, 4);
dynamicBody->CreateFixture(&myFixtureDef);
// Right green rectangle
b2Vec2 vertices[4];
vertices[0].Set(5, 0);
vertices[1].Set(6, 0);
vertices[2].Set(6, 0.5);
vertices[3].Set(5, 0.5);
polygonShape.Set(vertices, 4);
dynamicBody->CreateFixture(&myFixtureDef);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.