Share My Creation B4x - 2d Physics Library [Alpha]

Hi all,

playing around with b4j and creating a 2d physics engine. i know we have X2 i just find it sometimes a little bit to complex to make simple games. i love creating games using core library only and with this engine i can now. i cant tell anything about performance yet it is still in very early stage. maybe after adding some sprites and animation the performance will be bad but maybe i will be able to make something that is very simple to use and can get decent performance for small/mid games. (will not replace libgdx or ispritekit for sure and even not x2) but simple games with physics animation i think will be able to do.


PS: 3 libraries are checked in the library window

- B4xPages
- jCore
- jFX

🤓
 

Attachments

  • Screenshot 2026-10-27 000259.png
    Screenshot 2026-10-27 000259.png
    26.6 KB · Views: 151
Very nice.
Can you set the "physical" paramters like Gravity, Weight, Material etc. ?
 
Very nice.
Can you set the "physical" paramters like Gravity, Weight, Material etc. ?

Yep!

Code: Copy
Sub Class_Globals
    Public Position As Vec2
    Public Velocity As Vec2
    Public Force As Vec2
    Public Width As Vec2
    Public Rotation As Float
    Public AngularVelocity As Float
    Public Torque As Float
    Public Mass As Float
    Public InvMass As Float
    Public I As Float
    Public InvI As Float
    Public Friction As Float
    Public Restitution As Float
    Public GravityScale As Float
    Public Radius As Float
    Public ID As Int
    Public LocalVertices() As Vec2
    Public IsAwake As Boolean
    Public IdleTime As Float
    Public NeverDelete As Boolean
End Sub

Public Sub Initialize
    Position.Initialize(0, 0)
    Velocity.Initialize(0, 0)
    Force.Initialize(0, 0)
    Width.Initialize(0, 0)
    Rotation = 0.0f
    AngularVelocity = 0.0f
    Torque = 0.0f
    Friction = 0.2f
    Restitution = 0.0f
    GravityScale = 1.0f
    Radius = 0.0f
    IsAwake = True
    IdleTime = 0.0f
    NeverDelete = False
    
    BoxMath.BodyIDCounter = BoxMath.BodyIDCounter + 1
    ID = BoxMath.BodyIDCounter
End Sub
 
Back
Top