How can I recreate some body?

General discussion about the R.U.B.E editor
Post Reply
yulan6248
Posts: 12
Joined: Wed Jul 10, 2013 9:10 am

How can I recreate some body?

Post by yulan6248 »

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?
vkreal
Posts: 66
Joined: Sun Jan 13, 2013 7:29 pm

Re: How can I recreate some body?

Post by vkreal »

For your loading multiple rube files issue it's already been answered. you just need look for it on this forum
yulan6248
Posts: 12
Joined: Wed Jul 10, 2013 9:10 am

Re: How can I recreate some body?

Post by yulan6248 »

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..
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: How can I recreate some body?

Post by iforce2d »

yulan6248 wrote:... a way to recreate the same body
How about loading the json again?
yulan6248
Posts: 12
Joined: Wed Jul 10, 2013 9:10 am

Re: How can I recreate some body?

Post by yulan6248 »

...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..
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: How can I recreate some body?

Post by iforce2d »

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.
Post Reply