Games [XUI2D] Newton's Cradle Example

Erel

B4X founder
Staff member
Licensed User
Longtime User
A simple example:


1. It loads the objects.
2. Creates the rope joints.
3. That's it. Everything just happens.

A bit of code is required to draw the ropes.

Note that the restitution is set to 1.02 which is larger than the maximum value. This helps with preserving the motion energy.

It is included in the examples pack.

https://www.b4x.com/android/forum/threads/xui2d-example-pack.96454/
 

Marvel

Active Member
Licensed User
Why did we subtract the top vector from the hinge vector and then set it as the ropes LocalPointA vector?


B4X:
Dim TopPosition As B2Vec2 = hinge.BodyDef.Position.CreateCopy
            
'Subtract top bar body positiojn from hinge position
TopPosition.SubtractFromThis(top.Body.Position)
            
'Tie top bar with marble body with a ropeJoint
rope.Initialize(top.Body, bw.Body, TopPosition, X2.CreateVec2(0, 0), 1.5)
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…