cocos_add_physics_body2d
Add a physics body with a collider shape to a Cocos Creator 2D node in a single call, replacing the two-step process for attaching rigid bodies and colliders separately.
Instructions
Attach cc.RigidBody2D + a shape collider in one call.
Replaces the 2-call pattern every Bird / Pipe / Enemy needed:
rb = cocos_add_rigidbody2d(scene, node, body_type=2, ...)
col = cocos_add_box_collider2d(scene, node, width=W, ...)shape picks the collider: "box" / "circle" / "polygon".
The relevant shape knobs (width×height / radius /
points) are read based on the choice; the others are ignored.
Raises ValueError on unknown shape rather than silently attaching
a default.
body_type: 0=Static, 1=Kinematic, 2=Dynamic (default).
Returns {rigidbody_id, collider_id, shape}.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| scene_path | Yes | ||
| node_id | Yes | ||
| shape | No | box | |
| body_type | No | ||
| gravity_scale | No | ||
| linear_damping | No | ||
| angular_damping | No | ||
| fixed_rotation | No | ||
| bullet | No | ||
| awake_on_load | No | ||
| density | No | ||
| friction | No | ||
| restitution | No | ||
| is_sensor | No | ||
| tag | No | ||
| offset_x | No | ||
| offset_y | No | ||
| width | No | ||
| height | No | ||
| radius | No | ||
| points | No |