开发者

Box2d Loop Shape / create static ground shape in Cocos2D

开发者 https://www.devze.com 2023-02-28 15:32 出处:网络
Does anyone know what is the best method to create a st开发者_如何转开发atic ground body with many (~10000) vertices in Box2D (the version that comes with Cocos2D).

Does anyone know what is the best method to create a st开发者_如何转开发atic ground body with many (~10000) vertices in Box2D (the version that comes with Cocos2D).

This is what I do now for cubic beziers, it looks fine but runs a bit slow.

for (int i = 0; i<segments; i++) {
    CGPoint p2 = vertices[i+1];
    CGPoint p1 = vertices[i];
    b2PolygonShape poly;
    poly.SetAsEdge(b2Vec2(p1.x,p1.y), b2Vec2(p2.x, p2.y));
    groundBody->CreateFixture(&poly,0);
}

People talk about b2LoopShape but it doesn't seem like it's included in the Box2d version shipped with Cocos?

Any ideas?


For b2LoopShape, you need to replace external/Box2d with Box2D trunk.

  1. checkout Box2D trunk from box2d.
  2. replace cocos2d/external/Box2d with trunk/Box2D/Box2D.
  3. modify Xcode project for added Box2D files.
  4. modify some codes for renamed classes such as s/b2DebugDraw/b2Draw/.
0

精彩评论

暂无评论...
验证码 换一张
取 消