Jbox2d tutorial

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

+6
source share
3 answers

I ported the Hello World sample from the C ++ manual to jbox2d. This is just a line port. Obviously, you need to write a basic java program and call this code. You will also need to import several libraries, I had problems formatting my import in StackOverflow, so I exclude them. We hope your IDE takes care of the import.

// 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); } 
+6
source

This is not a straightforward programming issue, and is likely to be closed soon.

Regardless, games are not programmed in JBox2D, and JBox2D in one program. If you are looking for help using the jbox2d library, a quick google search showed one tutorial (for android, but I would expect the general use of the library to be pretty general), which looks like it might be useful - try the JBox2D user manual.

On the other hand, if you really want to know how to program games in general ... well, this is a much more important topic, and it is best to solve it using Google to search for game lessons. Just remember that game development is a common topic, not platform specific, so don't shy away from tutorials not written for Java, try and adapt their sample code instead, and you can learn even more!

+4
source

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

You can also watch a demo video of an example application here

+4
source

Source: https://habr.com/ru/post/886045/


All Articles