Games [XUI2D] How to make a rotating circle rotate in circle

budakbaru

Member
Licensed User
Longtime User
Hi all,
Can someone show me how to make a circle rotating at it's centre and also it rotate at another centre using XUI2D libraries. I mean like earth while rotating and also rotate around the sun. I saw the example of gear rotation in XUI2D example. How to make the gear a little bit moving.

Thanks.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
6DcCIGtwOG.gif


B4X:
Public Sub Start
    X2.Reset
    TileMap.Initialize(X2, File.DirAssets, "hello world with background.json", Null)
    TileMap.SetSingleTileDimensionsInMeters(X2.ScreenAABB.Width / TileMap.TilesPerRow, X2.ScreenAABB.Height / TileMap.TilesPerColumn)
    TileMap.PrepareObjectsDef(ObjectLayer)
    Earth = TileMap.CreateObject2ByName(ObjectLayer, "earth")
    Sun = TileMap.CreateObject2ByName(ObjectLayer, "sun")
    Earth.Body.ApplyForceToCenter(X2.CreateVec2(0, 30))
    Earth.Body.AngularVelocity = 3
    Dim v As B2Vec2 = Earth.Body.Position.CreateCopy
    v.SubtractFromThis(Sun.Body.Position)
    Dim rope As B2RopeJointDef
    rope.Initialize(Sun.Body, Earth.Body, X2.CreateVec2(0, 0), X2.CreateVec2(0, 0), v.Length)
    world.CreateJoint(rope)
    X2.Start
End Sub

Note that the tiled json includes a hinge. It can be deleted as it is not used.
 

Attachments

  • Project.zip
    236.1 KB · Views: 280
Last edited:
Top