如何使用 b2PolygonShape 顶点创建静态体

发布于 2024-10-05 19:25:51 字数 859 浏览 1 评论 0原文

我似乎无法在我的 Box2D Cocos2D 项目中创建带有顶点的 b2PolygonShape。我没有收到任何错误,但屏幕上没有显示任何内容。

如何使具有 b2PolygonShape 顶点的静态物体发挥作用?

我想将它与设置如下的列表一起使用:

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 / PTM_RATIO, -88.0f / PTM_RATIO)
};

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 / PTM_RATIO, -88.0f / PTM_RATIO)
};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨与橙与城 2024-10-12 19:25:51

下一步将指定形状的顶点

     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;

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;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文