开发者

jbox2d tutorial [closed]

开发者 https://www.devze.com 2023-02-25 18:55 出处:网络
开发者_运维技巧 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form.
开发者_运维技巧 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

can you tell me: where can I find tutorials "programming games in jbox2d"?


I have ported the Hello World sample from the C++ manual to jbox2d. This is just a line by line port. Obviously you need to write a basic java program and call this code. You will also need to import a number of libraries, I had trouble with the formatting of my imports in StackOverflow so I am excluding them. Hopefully your IDE will take care of the imports for you.

    // Static Body
    Vec2  gravity = new Vec2(0,-10);
    World world = new World(gravity);
    BodyDef groundBodyDef = new BodyDef();
    groundBodyDef.position.set(0, -10);
    Body groundBody = world.createBody(groundBodyDef);
    PolygonShape groundBox = new PolygonShape();
    groundBox.setAsBox(50, 10);
    groundBody.createFixture(groundBox, 0);

    // Dynamic Body
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.DYNAMIC;
    bodyDef.position.set(0, 4);
    Body body = world.createBody(bodyDef);
    PolygonShape dynamicBox = new PolygonShape();
    dynamicBox.setAsBox(1, 1);
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = dynamicBox;
    fixtureDef.density = 1;
    fixtureDef.friction = 0.3f;
    body.createFixture(fixtureDef);

    // Setup world
    float timeStep = 1.0f/60.0f;
    int velocityIterations = 6;
    int positionIterations = 2;

    // Run loop
    for (int i = 0; i < 60; ++i) {
        world.step(timeStep, velocityIterations, positionIterations);
        Vec2 position = body.getPosition();
        float angle = body.getAngle();
        System.out.printf("%4.2f %4.2f %4.2f\n", position.x, position.y, angle);
    }


I have developed one simple application using jBox2D and javaFX 2. You can find tutorial and source code for this application here.

Also you can watch application sample demo video here


This is not exactly a direct programming-related question, and thus will probably be closed soon.

Regardless, one does not program games in JBox2D, one programs games with JBox2D. If you're looking for help in using the jbox2d library, a quick Google search turned up one tutorial (for android, but I would expect the general use of the library to be quite general) that looks like it may be helpful - alternatively, try the JBox2D user manual.

On the other hand, if what you really want to know is how to program games in general... well, that's a far larger topic and one that is best solved with a Google search for game tutorials. Just remember that game-making is a general topic, not platform specific, so don't shy away from tutorials not written for Java - try and adapt their example code instead, and you may learn even more!

0

精彩评论

暂无评论...
验证码 换一张
取 消