The first version of XUI2D and the X2 framework are almost ready. Joints are now being added.
The joints feature is a very powerful feature of box2d and can be used to implement complicated physical structures.
X2TileMap was also improved and it now properly supports rotated objects.
There is almost no code in the above example except of the template code.
The objects are defined with Tiled editor:
This code adds the joints between the elements based on the "hinge" objects positions:
Good tutorial about joints: http://www.iforce2d.net/b2dtut/joints-overview
The joints feature is a very powerful feature of box2d and can be used to implement complicated physical structures.
X2TileMap was also improved and it now properly supports rotated objects.
There is almost no code in the above example except of the template code.
The objects are defined with Tiled editor:
This code adds the joints between the elements based on the "hinge" objects positions:
B4X:
Private Sub CreateChain
Dim elements As List
elements.Initialize
For Each ElementName As String In Array("pole 1", "chain 1", "chain 2", "chain 3", "chain 4", "chain 5", "chain 6", "pole 2")
elements.Add(TileMap.CreateObject2ByName(ObjectLayer, ElementName))
Next
For i = 0 To elements.Size - 2
CreateJoint(elements.Get(i), elements.Get(i + 1), "hinge " & (i + 1))
Next
End Sub
Private Sub CreateJoint(BodyA As X2BodyWrapper, BodyB As X2BodyWrapper, HingeName As String)
Dim revdef As B2RevoluteJointDef
revdef.Initialize(BodyA.Body, BodyB.Body, TileMap.GetObjectTemplateByName(ObjectLayer, HingeName).BodyDef.Position)
world.CreateJoint(revdef)
End Sub
Good tutorial about joints: http://www.iforce2d.net/b2dtut/joints-overview