简体   繁体   中英

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?

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 copies the data out of the body definition; it does not keep a pointer to the body definition. This means you can recycle a body definition to create multiple bodies.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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