PhysicsBox¶
PhysicsBox is a Compose Multiplatform physics layout container for Android and Desktop (JVM). It turns Composables into 2D physics bodies and renders their motion by applying translation and rotation during layout.
The runtime uses JBox2D on JVM platforms, providing stable rigid‑body simulation with fixed‑timestep stepping, boundaries, dragging, and collision callbacks.
Quick links¶
What you get¶
-
PhysicsBoxcontainer that drives simulation and layout. -
Modifier.physicsBodyto register Composables as physics bodies. -
Shapes: box, circle, polygon.
-
Dragging with joint‑style or direct control.
-
Collision, gravity simulation and step events.
Minimal snippet¶
val state = rememberPhysicsBoxState()
PhysicsBox(modifier = Modifier.fillMaxSize(), state = state) {
Box(
modifier = Modifier
.size(64.dp)
.clip(CutCornerShape(0.dp))
.physicsBody(key = "default_shape")
.background(Color.Red),
)
}