I'm using Libgdx. I did a simple json file in Physics Body Editor and I don't have any idea how could I import it into my physic world in libgdx.

Any idea will be appreciated.

P.S: Sorry if there are question with the same subject, I didn't find any of them.

  • 1
    \$\begingroup\$ One of the features listed for the Physics Body Editor is a 'Loader provided for LibGDX game framework'. The page I linked to also gives an example of how to use the loader. Isn't this what you're looking for? \$\endgroup\$ – NauticalMile Jun 3 '14 at 18:24

use this code. Though you must have got a file named app.java when you downloaded .zip of physics body editor. This code is from that file only which uses .json file from the editor.

// 0. Create a loader for the file saved from the editor. BodyEditorLoader loader = new BodyEditorLoader(Gdx.files.internal("data/test.json"));

    // 1. Create a BodyDef, as usual.
    BodyDef bd = new BodyDef();
    bd.type = BodyType.DynamicBody;

    // 2. Create a FixtureDef, as usual.
    FixtureDef fd = new FixtureDef();
    fd.density = 1;
    fd.friction = 0.5f;
    fd.restitution = 0.3f;

    // 3. Create a Body, as usual.
    bottleModel = world.createBody(bd);

    // 4. Create the body fixture automatically by using the loader.
    loader.attachFixture(bottleModel, "test01", fd, BOTTLE_WIDTH);
    bottleModelOrigin = loader.getOrigin("test01", BOTTLE_WIDTH).cpy();
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.