Get a grip on bodies of an imported b2world

General discussion about the R.U.B.E editor
Post Reply
rokus
Posts: 4
Joined: Mon Apr 06, 2015 1:11 pm

Get a grip on bodies of an imported b2world

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

Re: Get a grip on bodies of an imported b2world

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