XCode多边形精灵问题

时间:2013-02-04 18:51:39

标签: xcode cocos2d-iphone

我正在使用下面的代码尝试生成多边形形状精灵。我遇到了代码问题,任何人都可以发现它有什么问题吗?

   b2BodyDef woodBodyDef;
     woodBodyDef.position.Set(400/PTM_RATIO,100/PTM_RATIO);
     woodBodyDef.type = b2_dynamicBody;
     woodBodyDef.userData = _wood;
     _body = _world->CreateBody(&woodBodyDef);

     b2PolygonShape woodShape;

     int num = 4;
     b2Vec2 vertices[] = {
     b2Vec2(-137.0f/PTM_RATIO,-32.5f/PTM_RATIO),
     b2Vec2(-137.0f /PTM_RATIO,36.5f/PTM_RATIO),
     b2Vec2(137.0f /PTM_RATIO,36.5f/PTM_RATIO),
     b2Vec2(136.0f /PTM_RATIO, -32.5f/PTM_RATIO)
     };
     woodShape.Set(vertices, num);



     b2FixtureDef woodShapeDef;
     woodShapeDef.shape = &woodShape;
     woodShapeDef.density = 1.0f;
     woodShapeDef.friction = 1.0f;
     woodShapeDef.restitution = 0.5f;
     woodBodyDef.userData = _wood;
     _body = _world->CreateBody(&woodBodyDef);

1 个答案:

答案 0 :(得分:0)

我最好的猜测是顶点的顺序很重要。您可以按顺时针顺序定义它们,Box2D可能期望它们按逆时针顺序排列。它很容易验证,所以只需尝试一下,看看是否修复了断言(btw说多边形区域是< = 0)。