开发者

How to create a static body with b2PolygonShape vertices

I can´t seem to create a b2PolygonShape with vertices in my Box2D Cocos2D project. I get no errors but nothing shows up at the screen.

How do you get a static body with b2PolygonShape vertices to work?

I would like to use it with a list set up like this:

b2Vec2 verts[] = {
        b2Vec2(-194.5f / PTM_RATIO, 83.0f / PTM_RATIO),
        b2Vec2(-118.5f / PTM_RATIO, 65.0f / PTM_RATIO),
        b2Vec2(-77.5f / PTM_RATIO, 2.0f / PTM_RATIO),
        b2Vec2(3.5f / PTM_RATIO, -59.0f / PTM_RATIO),
        b2Vec2(62.5f / PTM_RATIO, -61.0f / PTM_RATIO),
        b2Vec2(108.5f / PTM_RATIO, -63.0f / PTM_RATIO),
        b2Vec2(138.5f / PTM_RATIO, -41.0f / PTM_RATIO),
        b2Vec2(169.5f / PTM_RATIO, 11.0f / PTM_RATIO),
        b2Vec2(184.5f / PTM_RATIO, 49.0f / PTM_RATIO),
        b2Vec2(218.5f / PTM_RATIO, 51.0f / PTM_RATIO),
        b2Vec2(219.5f / PTM_RATIO, -89.0f / PTM_RATIO),
        b2Vec2(-174.5f / PT开发者_JAVA百科M_RATIO, -88.0f / PTM_RATIO)
};


The next step will specifying the vertices to shape

     b2PolygonShape shape;
        int num = 4;
        b2Vec2 vertices[] = {
                    b2Vec2(10.5f / PTM_RATIO, 10.6f / PTM_RATIO),
                    b2Vec2(11.8f / PTM_RATIO, 18.1f / PTM_RATIO),
                    b2Vec2(-11.9f / PTM_RATIO, 18.3f / PTM_RATIO),
                    b2Vec2(-10.5f / PTM_RATIO, 10.8f / PTM_RATIO)
                };
        shape.Set(vertices, num);

b2FixtureDef fixtureDef; fixtureDef.shape = &shape;

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜