サイトのトップへ戻る

AndEngineドキュメント 日本語訳

BOX2D joints - 紹介。

jointsとは何か?おそらく、あなたはその名前からこの機能の目的を結論付けることができるかもしれませ。しかし誤解のない様に言うと、joints を使ってbodyを別のbodyにつなげることができるのです。 AndEngine には様々な種類のjoint があり、それらによって適切な物体が使えるようになり、あなたのゲームをより魅力的なものにしてくれます。 この記事を読む前に、以下の注意事項をしっかり読んでください!

重要: 以降の記事では (およびjointsに関連する次の記事では)、 最新版の AndEngine (GLES2 Anchor Center) と最新版のBOX2D 拡張を使用しています。 詳細情報については以下のリンクを参照してください。古いバージョンのAndEngineを使用すると、異なる挙動をしてエラーが発生する可能性があります。 古いバージョンのBOX2D 拡張を使用すると、新しい種類のjointsが実装されていないことがあります。 残念なことに、多くの人がこのスレッドをよく読まずに古いバージョンを使って、問題が起きたら質問を投稿してきます。 古いバージョンについてはサポートしていないので、自己責任での使用をお願いします。

私の記事では、以下の設定を使用しています。記事と同じ結果を表示するには、同じ設定を使用してください:

  • 最新版の AndEngine (GLES2 Anchor Center)。公式の git-hub からダウンロードできます。- ここをクリック (ソースをチェックアウトする際には、正しいブランチをダウンロードしてください!)
  • 最新版の Box2D。詳細情報については以下のスレッドを読んでください - ここをクリック (ソースをチェックアウトする際には、正しいブランチをダウンロードしてください!)
  • この拡張を使用した、Box2D デバッグドロー (nazgee氏にて公開)。これをダウンロードすることで、使用する PhysicalWorld (bodiesや joints) のデバッグが簡単に行えるようになります。 また、設定方法についての情報は - ここをクリックしてください (いつものように、それがanchor center ブランチになっているか確認してください)


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.

上記で一覧化して説明されているjointsについて、次の記事ではjointsに関連するさらに詳細な例、使用例、これらjointsを初期化する方法のチュートリアルがあります。

また、他にもAndEngineでサポートされているgearやmouseやpulley やfriction といったjointもあります。これらjontsの説明については、box2d マニュアルを参照してください。