box2d体形修改

发布于 2024-12-27 04:36:14 字数 133 浏览 1 评论 0原文

是否可以在分配后修改体内的形状,例如,我的游戏英雄身体有一个盒子形状,当我按下向下箭头时,我希望我的英雄蹲下女巫意味着我需要身体形状调整大小。

我已经在谷歌中搜索过,但似乎修改形状的主题并不那么受欢迎。如果不可能,也许您知道更好的方法。

Is it possible to modify a shape within a body after assigning it, for example I have a box shape for my game hero body, and when I press the down arrow I want my hero to crouch witch means that I need the body shape to be resized.

I've already searched in google but it appears that the topic of modyfing shapes is not so popular. If it's impossible maybe you know a better way of doing this.

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

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

发布评论

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

评论(2

药祭#氼 2025-01-03 04:36:14

我认为如果不更换形状并将它们重新连接到身体上,这是不可能的。

我的建议是有两个独立的身体,一个用于角色的底部,一个用于顶部,并通过棱柱形关节连接。

(有关关节的更多信息此处。)

I don't think it's possible without something like replacing the shapes and reattaching them to the body.

My suggestion would be to have two separate bodies, one for the bottom part of the character and one for the top part, connected with a prismatic joint.

(More info on joints here.)

愛上了 2025-01-03 04:36:14
- (void)scaleShape
{
    b2CircleShape shape;

    for (b2Fixture *f = self.yourb2Body->GetFixtureList(); f; f = f->GetNext())
    {
        shape = *(b2CircleShape *)f->GetShape();

        self.yourb2Body->DestroyFixture(f);
        shape.m_radius += 0.01;
        self.yourFixture.shape = &shape;
        self.yourFixture.isSensor = true;
        self.yourb2Body->CreateFixture(&self.yourFixture);
    }
- (void)scaleShape
{
    b2CircleShape shape;

    for (b2Fixture *f = self.yourb2Body->GetFixtureList(); f; f = f->GetNext())
    {
        shape = *(b2CircleShape *)f->GetShape();

        self.yourb2Body->DestroyFixture(f);
        shape.m_radius += 0.01;
        self.yourFixture.shape = &shape;
        self.yourFixture.isSensor = true;
        self.yourb2Body->CreateFixture(&self.yourFixture);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文