如何结合Box2d实体? [英] How to combine Box2d bodies?

查看:88
本文介绍了如何结合Box2d实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的纹理不仅是盒子或圆形,而且我的身体必须与该形状相同,所以我考虑将多个身体结合起来以达到自己想要的形状,这是否可能?还是有更好的方法来做到这一点?我在libgdx框架中使用Java.

I have a texture which is not just a box or circle and my body needs to be the same of this shape so I was thinking to combine multiple bodies to achieve my desired shape, is it even possible? or there are better ways to do it? I'm using java with libgdx framework.

推荐答案

The shape of body is being defined by Fixture instance. Since body can have multiple fixtures you can combine many shapes as you wish.

要创建许多灯具,您可以与其他人多次调用 createFixture 方法

To create many fixtures you jest call createFixture method many times with others FixtureDef objects like

FixtureDef fd1 = new FixtureDef();
FixtureDef fd2 = new FixtureDef();

...
fd1.shape = shape1;
fd2.shape = shape2;
...

body.createFixture(fd1);     
body.createFixture(fd1);

尽管请注意Box2D提供的

Although please notice that Box2D supports more than circles and rectangles by providing ChainShape that allows you to create any shape you want

ChainShape weird = new ChainShape();
weird.createLoop( new float[]{vertice1x, vertice1y, vertice2x, ...});

要加入团体,请联合(请在此处)机制,但我想这不是您想要的

To join bodies there is Joint (take a look here) mechanism but I guess it's not what you want here

这篇关于如何结合Box2d实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆