如何组合 Box2d 实体?

How to combine Box2d bodies?(如何组合 Box2d 实体?)
本文介绍了如何组合 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.

推荐答案

body的形状由Fixture 实例.由于 body 可以有多个固定装置,因此您可以根据需要组合多种形状.

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 方法 FixtureDef 对象,如

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 通过提供 physics/box2d/ChainShape.html" rel="nofollow">ChainShape 可以让你创建任何你想要的形状

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, ...});

要加入机构,有 Joint(看看 这里) 机制,但我想这不是你想要的

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

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

quot;Char cannot be dereferencedquot; error(“Char 不能被取消引用错误)
Java Switch Statement - Is quot;orquot;/quot;andquot; possible?(Java Switch 语句 - 是“或/“和可能的?)
Java Replace Character At Specific Position Of String?(Java替换字符串特定位置的字符?)
What is the type of a ternary expression with int and char operands?(具有 int 和 char 操作数的三元表达式的类型是什么?)
Read a text file and store every single character occurrence(读取文本文件并存储出现的每个字符)
Why do I need to explicitly cast char primitives on byte and short?(为什么我需要在 byte 和 short 上显式转换 char 原语?)