Preface:This blog post explains how to use jbox2d 2.1.2 on the Android platform. There are very few tutorials on jbox2d on the Internet, and there are fewer tutorials related to Android. I have been studying jbox2d for more than a month.
The engine is really good. It is an excellent simulation of the stress of the real world. The Angry Birds that swept the world some time ago were made with the box2d engine! I am using the version is jbox2d-2.1.2, the official forum to download this version is not available in Android platform, there are some small errors, later, after a period of research, I modified the source code to compile a jar package suitable for the Android platform, and the efficiency was optimized!
Download Engine: jbox2d4android_2.1.2.1
Section 1 create a physical world:
Box2d is actually a real physical world, and a world needs a range (of course, our world does not know that there is a range). The Versions earlier than box2d2.1.2 have a boundary concept, 2.1.2 is no longer available, more relevant to the concept of the physical world!
First lookCode
World; // The World object vec2 gravity = new vec2 (0.0f, 10.0f); // The World's gravity is: X axis, Y axis, here we give 10 N/m2 a little bigger than the real world = New World (gravity, true); // create the world: gravity, whether to allow static objects to sleep
This physical world has been created!
Joint Learning 1. Weld Joints:
Weldjoint: Used to fix two objects
Creation method:
Weldjointdef jointdef = new weldjointdef (); jointdef. initialize (body, body2, vec2); // vec2: Fixed Points of two objects
World. createjoint (jointdef );
To be continued...