What are joints? You probably can easily conclude possible purposes of this features by their names, but to be clear, we can use joints to connect bodies with different bodies. There are various joint types available in AndEngine which gives you great possibility to make make your game even more attractive, by providing proper physics. Please read carefully note posted below before reading this article!
IMPORTANT: in following article (and next articles related with joints) I use LATEST version of AndEngine (GLES2 Anchor Center) and latest version of the BOX2D extension, please see links below to get more information, using older version of the AndEngine, will lead to different behaviour and possible errors, using older version of the BOX2D extension, will lead to missing new joint types. Unfortunately many people do not read my threads carefully, using older versions and latter posting about issues. I will not provide support for older versions, use it on your own risk.
In my articles, I use following configuration, use the same to receive same results:
latest version of the AndEngine (GLES2 Anchor Center) you can download it from the official git-hub - CLICK HERE (while checking out the source, make sure to download proper branch!)
latest version of the Box2D, for more information, please read following thread - CLICK HERE (while checking out the source, make sure to download proper branch!)
Box2D debug draw (published by nazgee) using this extension, we will be easily able to debug our physical world (bodies, joints) to download it and also information about how to setup, please - CLICK HERE (As always make sure it is proper, anchor center branch)
1. Joint の種類:
以下にはいくつかの種類のjoinに関する簡単な説明があります。AndEngine とBOX2D 拡張は組み合わせて使用することが可能です。
これらの説明のいくつかは、公式のBox2d マニュアルページのものや、私独自の解釈が使用されているので注意してください。
For joints used below, you will be able to read more informative, separated articles showing example usage, initializing such joints etc.
Revolute joint - A revolute joint forces two bodies to share a common anchor point, often called a hinge point. The revolute joint has a single degree of freedom: the relative rotation of the two bodies. This is called the joint angle.
Distance joint - it maintains distance between two bodies, by specifying anchor points for those joints, some advantages and possibilities: you can manipulate distance on the runtime, you can also adjust damping ratio and mass-spring-damper frequency in Hertz to achieve different behaviour (you will often need to "play" with its values before achieving result you were thinking of)
Prismatic joint - Prismatic joint allows for relative translation of two bodies along a specified axis. A prismatic joint prevents relative rotation. Therefore, a prismatic joint has a single degree of freedom. Still do not understand how does it work? Lets imagine slider in your pants.
Weeld joint - It attempts to constrain all relative motion between two bodies, in another words, it bounds two bodies together
Rope joint - Restricts the maximum distance between two points. This can be useful to prevent chains of bodies from stretching, even under high load, usually we use this joint to connect multiple small bodies to each other, to simulate proper rope, thought it usually its not performance friendly, because requires many dynamic bodies.
Wheel joint - The wheel joint restricts a point on bodyB to a line on bodyA. The wheel joint also provides a suspension spring, as you can conclude from joint name, we can use it to simulate wheel of the car for instance - with realistic suspension effect.
Below you can find brief description of some joint types, you can use by combining AndEngine and BOX2D extension. Note some of those descriptions were used from official Box2d manual page, or my own interpretation. For joints used below, you will be able to read more informative, separated articles showing example usage, initializing such joints etc.
Revolute joint - A revolute joint forces two bodies to share a common anchor point, often called a hinge point. The revolute joint has a single degree of freedom: the relative rotation of the two bodies. This is called the joint angle.
Distance joint - it maintains distance between two bodies, by specifying anchor points for those joints, some advantages and possibilities: you can manipulate distance on the runtime, you can also adjust damping ratio and mass-spring-damper frequency in Hertz to achieve different behaviour (you will often need to "play" with its values before achieving result you were thinking of)
Prismatic joint - Prismatic joint allows for relative translation of two bodies along a specified axis. A prismatic joint prevents relative rotation. Therefore, a prismatic joint has a single degree of freedom. Still do not understand how does it work? Lets imagine slider in your pants.
Weeld joint - It attempts to constrain all relative motion between two bodies, in another words, it bounds two bodies together
Rope joint - Restricts the maximum distance between two points. This can be useful to prevent chains of bodies from stretching, even under high load, usually we use this joint to connect multiple small bodies to each other, to simulate proper rope, thought it usually its not performance friendly, because requires many dynamic bodies.
Wheel joint - The wheel joint restricts a point on bodyB to a line on bodyA. The wheel joint also provides a suspension spring, as you can conclude from joint name, we can use it to simulate wheel of the car for instance - with realistic suspension effect.
For joints listed and described above, you will find more detailed examples, sample usages, and tutorial how to initialize those joints, in next articles, related to the joins.
There are also few more joints supported by AndEngine, such as gear, mouse, pulley and friction joint, for description of those joints, please refer to the box2d manual.