Page 1 of 1

Get a grip on bodies of an imported b2world

Posted: Tue Apr 14, 2015 10:47 am
by rokus
Hi,

it's super simple to import a RUBE-json with b2djson.readFromString. But since i use some of the bodies as player characters, i want to hold pointers to the specific bodies to get their position.
The Box2D manual says: "You usually keep pointers to all the bodies you create." With readFromString (or readFromFile) this is impossible.

I tried to store the b2djson as class member instead and use getBodiesByName, then get the one i need. That seems a) rather complicated and b) do i run in segfaults.

Long story short: How do i get permanently valid pointers on b2bodies that i can use to get their position?

C++, Cocos2d-x 3, Android, btw.

Re: Get a grip on bodies of an imported b2world

Posted: Tue Apr 14, 2015 6:37 pm
by iforce2d
Can't you keep the pointers you get from getBodiesByName immediately after loading? They will remain valid unless you do DestroyBody. The b2dJson is not intended to be stored after the loading process.