I'm using b2dJson and I'd like to ask how I can load the rube file and get the `fixtureDef`, `bodyDef` instead of the `fixture` and `body`. I ask this because in my game I need to dynamically create new shapes, and I don't know if there's a simple way to copy the same body.
Another problem I've encountered is that I have to design all the elements in the same rube file because different rube files will share different `b2Worlds` when they load up. That means there isn't a simple way to add the body loaded from one rube file into the world created from another rube file (again, if I can get the `Def`s it might be straightforward). The implication is that I can't design the player in one file and use it across different chapters in different files.
I think these problems are fairly common and probably someone has already had solutions for them. I'm fairly inexperienced with Box2D so can that someone share some tips?
How can I recreate some body?
Re: How can I recreate some body?
For your loading multiple rube files issue it's already been answered. you just need look for it on this forum
Re: How can I recreate some body?
Just checked this out https://www.iforce2d.net/forums/viewtopic.php?f=6&t=176 and it solves my problem with multiple files. However I still can't seem to think of a way to recreate the same body (with all the fixtures and possibly joints wired up of course)....? That would mean that I have to adopt a static design over a dynamic one..
Re: How can I recreate some body?
How about loading the json again?yulan6248 wrote:... a way to recreate the same body
Re: How can I recreate some body?
...that's indeed one of the solutions but I was looking for something more elegant...It's also limited in the way that you have to put each body that you would like to reproduce in separate files, which is a bit troublesome..
Re: How can I recreate some body?
Perhaps the functions of b2dJson for replicating bodies would be useful:
http://www.iforce2d.net/b2djson/#replicating
It's not exactly the 'def' of the body but it's very close, and probably easier to use.
But if you want to reproduce a complex structure of multiple bodies with joints connecting them, I'm afraid that putting the whole structure in a separate file is as elegant a solution as we have at the moment.
http://www.iforce2d.net/b2djson/#replicating
It's not exactly the 'def' of the body but it's very close, and probably easier to use.
But if you want to reproduce a complex structure of multiple bodies with joints connecting them, I'm afraid that putting the whole structure in a separate file is as elegant a solution as we have at the moment.