Games [XUI2D] Joints Example


Staff member
Licensed User

Joints connect two bodies.
There are all kinds of joints and they can be used to implement interesting physical solutions.

This example demonstrates three types of joints:

WeldJoint - Very simple joint. The two bodies are strictly connected with zero movement between the bodies. Note that it is possible that there will be some relative movement if strong forces act on the bodies.
WeldJoint is used here for the fence graphics. We want the fence to move together with the "chain" element.
We could have achieved the same effect by creating a body with two fixtures. However this is not possible with X2TiledMap. The WeldJoint makes it simple.

RopeJoint - Defines the maximum distance between two bodies (more accurately, between a specific point in body A and a specific point in body B).

RevoluteJoint - This is a more powerful joint. I'll quote this nice tutorial:
"The revolute joint can be thought of as a hinge, a pin, or an axle. An anchor point is defined on each body, and the bodies will be moved so that these two points are always in the same place, and the relative rotation of the bodies is not restricted.

Revolute joints can be given limits so that the bodies can rotate only to a certain point. They can also be given a motor so that the bodies will try to rotate at a given speed, with a given torque. Common uses for revolute joints include:
  • wheels or rollers
  • chains or swingbridges (using multiple revolute joints)
  • rag-doll joints
  • rotating doors, catapults, levers"
In this example the revolute joints are only used as hinges. The motors are not enabled.
The joints make the bridge flexible.

There is almost no code in this example. The bodies and joints are defined in the map json file.


There is a new 'tag' property. Make sure to update the custom properties: View - Object Types Editor - File - Import .

The tag is used here to define the joints. For example:
revolute, chain 2, chain 3

This means that it will create a RevoluteJoint in the hinge position with the two specified bodies.

The rope drawing requires special handling as there is no body and the rope size is dynamic.

Depends on XUI2D v0.96

This example is included in the examples pack: