jbox2d教程

发布于 2024-11-01 08:48:38 字数 57 浏览 4 评论 0原文

你能告诉我吗: 在哪里可以找到教程“jbox2d 中的游戏编程”

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深者入戏 2024-11-08 08:48:38

我已将 C++ 手册中的 Hello World 示例移植到 jbox2d。这只是逐行端口。显然你需要编写一个基本的java程序并调用这段代码。您还需要导入许多库,我在 StackOverflow 中导入的格式时遇到了问题,因此我将它们排除在外。希望您的 IDE 能够为您处理导入工作。

    // 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 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);
    }
叹梦 2024-11-08 08:48:38

我使用 jBox2D 和 javaFX 2 开发了一个简单的应用程序。您可以找到该应用程序的教程和源代码 此处

您还可以在此处观看应用程序示例演示视频

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

抠脚大汉 2024-11-08 08:48:38

这不完全是一个直接与编程相关的问题,因此可能很快就会结束。

无论如何,人们不会 JBox2D 中编写游戏,而是使用 JBox2D 编写游戏。如果您正在寻求有关使用 jbox2d 库的帮助,可以通过 Google 快速搜索 一个教程(适用于android,但我希望该库的一般用法非常一般),看起来像它可能会有所帮助 - 或者,尝试 JBox2D 用户手册

另一方面,如果您真正想知道的是如何对一般游戏进行编程……那么,这是一个更大的主题,最好通过 Google 搜索游戏教程来解决。请记住,游戏制作是一个通用主题,而不是特定于平台的主题,因此不要回避不是为 Java 编写的教程 - 尝试改编他们的示例代码,您可能会学到更多!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文