简体   繁体   English

Box2D一种用于多主体的夹具

[英]Box2D One fixture for multiple bodies

I have a repeatable block type that uses the same body definition and fixture definition. 我有一个可重复的块类型,它使用相同的主体定义和夹具定义。 Should I create the bodyDef and fixtureDef for every block, or just change the position for bodyDef and reuse the same objects every time? 我应该为每个块创建bodyDef和fixtureDef,还是仅更改bodyDef的位置并每次重用相同的对象?

You can't have one fixture for multiple bodies, like the title says, as each fixture is attached to a particular body, and destroyed with it. 您不能像多个标题一样拥有一个用于多个物体的固定装置,因为每个固定装置都附加到特定的物体上并随其销毁。

However, you can use the same body definition to create multiple bodies, and the same fixture definition to create multiple fixtures (possibly attached to different bodies). 但是,可以使用相同的实体定义创建多个实体,并使用相同的夹具定义创建多个夹具(可能附加到不同的实体)。 It is also better practice, since it allows to save memory and lines of code. 这也是更好的做法,因为它可以节省内存和代码行。

It is stated in section 7.2 of the Box2D manual : Box2D手册的 7.2节中对此进行了说明:

Box2D copies the data out of the body definition; Box2D从主体定义中复制数据; it does not keep a pointer to the body definition. 它没有保持指向主体定义的指针。 This means you can recycle a body definition to create multiple bodies. 这意味着您可以回收实体定义以创建多个实体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM