Games [XUI2D] First Joints Demo

Discussion in 'Game Development' started by Erel, Aug 21, 2018.

  1. Erel

    Erel Administrator Staff Member Licensed User

    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:

    [​IMG]

    This code adds the joints between the elements based on the "hinge" objects positions:
    Code:
    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
     
    aeric, Jaames, BPak and 11 others like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice